# Messages (Anthropic)

Send messages using the Anthropic-compatible Genesis Messages API and return generated content.

```text
POST https://token.moi.matrixorigin.cn/v1/messages
```

## Before you call

Prepare [credentials](../../../../guides/genesis/api-keys.md#choose-a-credential-type) with Genesis access and a model ID that supports the Messages request shape.

## Request body

Replace `$GENESIS_ACCESS_TOKEN` with an access token or service-account API key, and `$MODEL_ID` with the model ID to call.

:::::::{div} mo-api-tabs
::::::{tab-set}
:::::{tab-item} Request example

```bash
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":"Explain data lineage in one sentence."}],
    "stream": false
  }'
```

:::::
:::::{tab-item} Parameter description

::::{tab-set}
:::{tab-item} Parameters

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `model` | string | Yes | Anthropic Messages model ID to call. |
| `max_tokens` | integer | Yes | Maximum tokens to generate. |
| `messages` | array of object | Yes | Ordered list of messages to submit. |
| `stream` | boolean | No | Set to `true` to return Anthropic Messages SSE events. |

:::
:::{tab-item} Message item

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `role` | string | Yes | Message role. |
| `content` | string | Yes | Text content of the message. |

:::
::::

:::::
::::::
:::::::

## Successful response

The service returns generated content in the `content` array.

:::::::{div} mo-api-tabs mo-api-response-tabs
::::::{tab-set}
:::::{tab-item} Response example

```json
{
  "id": "<MESSAGE_ID>",
  "type": "message",
  "role": "assistant",
  "model": "<MODEL_ID>",
  "content": [{"type":"text","text":"A transaction executes a group of operations as a whole to preserve data consistency."}],
  "stop_reason": "end_turn"
}
```

:::::
:::::{tab-item} Field description

::::{tab-set}
:::{tab-item} Common fields

| Field | Type | Description |
| --- | --- | --- |
| `id` | string | Identifier for this Message. |
| `type` | string | Response type; the example is `message`. |
| `role` | string | Role of the generated message. |
| `model` | string | Model ID that processed the request. |
| `content` | array of object | Generated content items. |
| `stop_reason` | string or null | Reason the current generation stopped. |

:::
:::{tab-item} Content item

| Field | Type | Description |
| --- | --- | --- |
| `type` | string | Content type; the example is `text`. |
| `text` | string | Generated text when the content type is `text`. |
| `thinking` | string | Reasoning content when the content type is `thinking`. |

:::
::::

:::::
::::::
:::::::

## Error response

:::::::{div} mo-api-tabs mo-api-response-tabs
::::::{tab-set}
:::::{tab-item} Response example

```json
{"error":{"message":"<human-readable error message>","type":"<error type; may be omitted>","code":"<error code; may be omitted>"}}
```

:::::
:::::{tab-item} Field description

::::{tab-set}
:::{tab-item} Common fields

| Field | Type | Description |
| --- | --- | --- |
| `error` | object | Error object. |

:::
:::{tab-item} Error object

| Field | Type | Description |
| --- | --- | --- |
| `message` | string | Human-readable error message. |
| `type` | string | Error category returned by the model service; it may be omitted. |
| `code` | string or null | Error code returned by the model service; it may be omitted. |

:::
::::

:::::
::::::
:::::::
