Create a Message¶
Generate a reply using the Anthropic Messages format and receive text or thinking blocks.
POST https://token.moi.matrixorigin.cn/v1/messages
Before you begin¶
Prepare a personal access token or service account API key for Genesis. See Access credentials for credential selection and permissions.
Use List callable models to select a model that supports Messages.
Request body¶
Replace $GENESIS_ACCESS_TOKEN and $MODEL_ID with your credential and the selected model ID.
curl -X POST \
"https://token.moi.matrixorigin.cn/v1/messages" \
-H "Authorization: Bearer $GENESIS_ACCESS_TOKEN" \
-H 'Content-Type: application/json' \
-d '{
"model": "'"$MODEL_ID"'",
"max_tokens": 256,
"messages": [
{
"role": "user",
"content": [
{
"type": "text",
"text": "Reply with OK."
}
]
}
],
"stream": false
}'
The fields below cover text messages. Images, documents, tools, and explicit thinking configuration require corresponding model capabilities.
Parameter |
Type |
Required |
Description |
|---|---|---|---|
|
string |
Yes |
Selected model ID from |
|
integer |
Yes |
Maximum generated tokens; use a positive integer. |
|
array of object |
Yes |
Nonempty messages in conversation order. |
|
string |
Yes |
Message role: |
|
string or array of object |
Yes |
Text or text blocks. |
|
string |
Required for a text block |
Use |
|
string |
Required for a text block |
Nonempty text content. |
|
boolean |
No |
Set to |
Successful response¶
A non-streaming request returns the generated message, which can contain text or thinking blocks.
{
"id": "msg-example",
"type": "message",
"role": "assistant",
"model": "MODEL_ID",
"content": [
{
"type": "text",
"text": "OK"
}
],
"stop_reason": "end_turn",
"usage": {
"input_tokens": 12,
"output_tokens": 1
}
}
Field |
Type |
Description |
|---|---|---|
|
string |
Message identifier. |
|
string |
Object type |
|
string |
Message role |
|
string |
Model that processed the request. |
|
array of object |
Generated blocks. Read text or thinking content according to the type. |
|
string |
Block type: |
|
string |
Generated text in a text block. |
|
string |
Content of a thinking block. |
|
string |
Signature returned with a thinking block; preserve it when present. |
|
string or null |
Stop reason, such as |
|
object |
Token usage for this request. |
|
integer |
Input tokens. |
|
integer |
Output tokens. |
|
integer |
Cache-write input tokens, when returned. |
|
integer |
Cache-read input tokens, when returned. |
Streaming response¶
Set stream to true in the request body to receive generated content incrementally. The service sends server-sent events (SSE) and ends the message with message_stop.
curl -N -X POST \
"https://token.moi.matrixorigin.cn/v1/messages" \
-H "Authorization: Bearer $GENESIS_ACCESS_TOKEN" \
-H 'Content-Type: application/json' \
-d '{
"model": "'"$MODEL_ID"'",
"max_tokens": 256,
"messages": [
{
"role": "user",
"content": [
{
"type": "text",
"text": "Reply with OK."
}
]
}
],
"stream": true
}'
event: message_start
data: {"type":"message_start","message":{"id":"msg-example","type":"message","role":"assistant","content":[],"usage":{"input_tokens":12,"output_tokens":0}}}
event: content_block_start
data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""}}
event: content_block_delta
data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"OK"}}
event: content_block_stop
data: {"type":"content_block_stop","index":0}
event: message_delta
data: {"type":"message_delta","delta":{"stop_reason":"end_turn"},"usage":{"output_tokens":1}}
event: message_stop
data: {"type":"message_stop"}
Field |
Type |
Description |
|---|---|---|
|
string |
Event type matching the SSE event name, such as |
|
object |
Initial message in |
|
integer |
Content block index linking its start, delta, and stop events. |
|
object |
Initial block in |
|
string |
Initial block type; |
|
string |
Initial text of the block. |
|
object |
Content delta or message state update; interpret it by event type. |
|
string |
Content delta type; |
|
string |
Incremental text to append to the same block. |
|
string |
Content in a thinking delta, when present. |
|
string |
Generation stop reason returned by |
|
object |
Token usage returned by |
|
integer |
Number of output tokens generated. |
Buffer and parse complete SSE events. message_start starts the message; process content_block_start, content_block_delta, and content_block_stop by block index. message_delta can include the stop reason and usage, and message_stop ends the message. If the connection closes before message_stop, the content received so far may be incomplete.
Error response¶
A missing model ID returns HTTP 400. Supply the model ID before sending the request again.
{
"error": {
"message": "missing required parameter: model",
"type": "invalid_request",
"code": "invalid_request"
}
}
Field |
Type |
Description |
|---|---|---|
|
object |
Error details. |
|
string |
Error description; the example indicates a missing model ID. |
|
string |
Error type; may be omitted by a model service. |
|
string or null |
Error code; may be omitted by a model service. |
Next steps¶
To check the input length before generation, use Count input tokens.