Text generation¶
POST /api/v5/chat/completions
Generates text. This endpoint is based on the OpenAI-compatible Chat Completions protocol. You submit a model name and the conversation messages and choose between a streaming (SSE) and a non-streaming response; temperature and sampling parameters control generation, and the response returns the generated content together with token usage statistics.
Supported access tokens¶
- AtomGit user access tokens
Anonymous access allowed¶
This endpoint does not allow anonymous access.
Request parameters¶
| Parameter | Location | Type | Required | Description |
|---|---|---|---|---|
Authorization |
header | string | Yes | User personal token; pass it as Bearer <token> |
Request Body:
The request body is an OpenAI-compatible Chat Completions request JSON with the following fields:
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"model": {
"description": "Model name",
"type": "string"
},
"messages": {
"description": "List of conversation messages",
"type": "array",
"items": {
"type": "string"
}
},
"stream": {
"description": "Whether to stream the response (SSE). When true, the response is text/event-stream; otherwise it is application/json",
"type": "boolean",
"default": false
},
"temperature": {
"description": "Temperature",
"type": "number",
"default": 0.7
},
"top_p": {
"description": "top_p sampling parameter",
"type": "number",
"default": 0.7
},
"top_k": {
"description": "top_k sampling parameter",
"type": "integer",
"default": 50
},
"frequency_penalty": {
"description": "Frequency penalty",
"type": "number",
"default": 1.0
},
"maxTokens": {
"description": "Maximum number of tokens",
"type": "integer"
}
},
"required": ["model", "messages"]
}
Response parameters¶
| Field | Type | Always returned | Nullable | Description |
|---|---|---|---|---|
trace_id |
string | Yes | No | Unique identifier of the request |
choices |
array | Yes | No | List of generated results |
ext |
string | Yes | Yes | Extension field, usually null |
usage |
object | Yes | No | Token usage statistics |
choices element object
| Field | Type | Always returned | Nullable | Description |
|---|---|---|---|---|
choices[].index |
integer | Yes | No | Result index |
choices[].finish_reason |
string | No | Yes | Reason the generation finished; may be null |
choices[].delta |
object | Yes | No | Incremental content |
choices[].delta object
| Field | Type | Always returned | Nullable | Description |
|---|---|---|---|---|
choices[].delta.content |
string | No | Yes | Fragment of the generated content |
usage object
| Field | Type | Always returned | Nullable | Description |
|---|---|---|---|---|
usage.prompt_tokens |
integer | Yes | No | Number of tokens consumed by the prompt |
usage.completion_tokens |
integer | Yes | No | Number of tokens consumed by the completion |
usage.total_tokens |
integer | Yes | No | Total number of tokens |
usage.think_tokens |
integer | No | Yes | Number of tokens consumed by the reasoning process |
Error response¶
This endpoint has no business-level error response; failures are reported through the HTTP status code (see "HTTP status codes").
HTTP status codes¶
| Status code | Description |
|---|---|
200 |
Success (OK) |
401 |
Authentication required (Requires authentication) |
403 |
Access forbidden (Forbidden) |
404 |
Request path does not exist |
405 |
Request method not supported |
429 |
Too many requests; rate limit triggered |
500 |
Internal system error |
Request example¶
Parameter notes¶
The example below is a non-streaming call. Replace <model> with the model name and <messages> with the list of conversation messages. This endpoint does not allow anonymous access, so you must identify the caller with Authorization: Bearer <token> (replace <token> with your AtomGit user access token).
cURL¶
curl -X POST 'https://api.atomgit.com/api/v5/chat/completions' \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-H 'Authorization: Bearer <token>' \
-d '{
"model": "<model>",
"messages": ["<message>"],
"temperature": 0.7,
"stream": false
}'
JavaScript¶
// Native fetch (Node.js 18+ / browsers)
const response = await fetch("https://api.atomgit.com/api/v5/chat/completions", {
method: "POST",
headers: {
"Content-Type": "application/json",
"Accept": "application/json",
"Authorization": "Bearer <token>",
},
body: JSON.stringify({
model: "<model>",
messages: ["<message>"],
temperature: 0.7,
stream: false,
}),
});
if (!response.ok) {
throw new Error(`Request failed: ${response.status}`);
}
const data = await response.json();
console.log(data);
Python¶
import requests
resp = requests.post(
"https://api.atomgit.com/api/v5/chat/completions",
headers={
"Content-Type": "application/json",
"Accept": "application/json",
"Authorization": "Bearer <token>",
},
json={
"model": "<model>",
"messages": ["<message>"],
"temperature": 0.7,
"stream": False,
},
timeout=10,
)
resp.raise_for_status()
print(resp.json())
Response example¶
Status code: 200
{
"trace_id": "045560649c7c483e80eb196e2bc95d38",
"choices": [
{
"index": 0,
"finish_reason": null,
"delta": {
"content": "This is a streamed content fragment"
}
}
],
"ext": null,
"usage": {
"prompt_tokens": 11,
"completion_tokens": 146,
"total_tokens": 157,
"think_tokens": null
}
}
Error codes¶
| Error code | Description |
|---|---|
401 |
Unauthenticated or invalid credentials (missing or invalid access credentials) |
400 |
Invalid parameters or the request cannot be parsed |
404 |
Request path does not exist |
405 |
Request method not supported |
429 |
Too many requests; rate limit triggered |
500 |
Internal system error |
Markdown source: View on AtomGit·Content from the open-source project gitcode-dev/atomgit-api-doc