Chat Completions¶
Send messages to a Genesis model that supports Chat Completions and return generated content.
POST https://token.moi.matrixorigin.cn/v1/chat/completions
Before you call¶
Prepare credentials with Genesis access and obtain a model ID from List models. Confirm that the selected model supports Chat Completions.
Request body¶
Replace $GENESIS_ACCESS_TOKEN with an access token or service-account API key, and $MODEL_ID with the model ID to call.
curl -X POST \
"https://token.moi.matrixorigin.cn/v1/chat/completions" \
-H "Authorization: Bearer $GENESIS_ACCESS_TOKEN" \
-H 'Content-Type: application/json' \
-d '{
"model": "'"$MODEL_ID"'",
"messages": [{"role": "user", "content": "Explain the purpose of a database transaction in one sentence."}],
"max_tokens": 128
}'
Field |
Type |
Required |
Description |
|---|---|---|---|
|
string |
Yes |
Chat Completions model ID to call. |
|
array of object |
Yes |
Ordered list of messages to submit. |
|
integer |
No |
Maximum output tokens for this generation; use only values supported by the selected model. |
|
number |
No |
Sampling temperature; set only when the selected model supports it. |
|
boolean |
No |
Set to |
The following table expands each item in the example messages array.
Field |
Type |
Required |
Description |
|---|---|---|---|
|
string |
Yes |
Message role. |
|
string |
Yes |
Text content of the message. |
Successful response¶
The service returns a model-generated message.
{
"id": "<COMPLETION_ID>",
"object": "chat.completion",
"model": "<MODEL_ID>",
"choices": [
{
"index": 0,
"message": {"role": "assistant", "content": "A transaction executes a group of operations as a whole to preserve data consistency."},
"finish_reason": "stop"
}
]
}
Field |
Type |
Description |
|---|---|---|
|
string |
Identifier for this Completion. |
|
string |
Response object type; the example is |
|
string |
Model ID that processed the request. |
|
array of object |
List of generated results. |
The following table expands each item in the example choices array.
Field |
Type |
Description |
|---|---|---|
|
integer |
Position of this result in the list. |
|
object |
Assistant message. |
|
string |
Reason the current generation ended. |
The following table expands the example choices[].message object.
Field |
Type |
Description |
|---|---|---|
|
string |
Message role. |
|
string |
Text generated by the assistant. |
Streaming response¶
Set stream to true and send Accept: text/event-stream to request streaming output. The service returns text/event-stream; continue reading incremental content from events until data: [DONE] arrives. An error before the stream is established is a JSON error object with the same shape as Error response.
curl -N -X POST \
"https://token.moi.matrixorigin.cn/v1/chat/completions" \
-H "Authorization: Bearer $GENESIS_ACCESS_TOKEN" \
-H 'Content-Type: application/json' \
-H 'Accept: text/event-stream' \
-d '{"model":"'"$MODEL_ID"'","messages":[{"role":"user","content":"Explain the purpose of a primary key in one sentence."}],"stream":true}'
data: {"object":"chat.completion.chunk","choices":[{"delta":{"content":"A primary key"}}]}
data: {"object":"chat.completion.chunk","choices":[{"delta":{"content":" uniquely identifies each row in a table."}}]}
data: [DONE]
Field |
Type |
Description |
|---|---|---|
|
string |
Event object type; the example is |
|
array of object |
Incremental results in the current event. |
|
event marker |
Normal completion marker; mark the result complete only after receiving it. |
Field |
Type |
Description |
|---|---|---|
|
object |
Incremental object. |
Field |
Type |
Description |
|---|---|---|
|
string |
Append it to the current text when present. |
Error response¶
{"error":{"message":"<human-readable error message>","type":"<error type; may be omitted>","code":"<error code; may be omitted>"}}
Field |
Type |
Description |
|---|---|---|
|
object |
Error object. |
Field |
Type |
Description |
|---|---|---|
|
string |
Human-readable error message. |
|
string |
Error category returned by the model service; it may be omitted. |
|
string or null |
Error code returned by the model service; it may be omitted. |
Next steps¶
For streaming reads, see Streaming response above. For other request shapes, see Responses and Messages (Anthropic).