Messages (Anthropic)
Creates a model response using the Anthropic-compatible API format.
Endpoint
POST https://gateway.mytokengate.com/v1/messagesRequest Example
curl --request POST \
--url https://gateway.mytokengate.com/v1/messages \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '{
"model": "claude-sonnet-4-6",
"messages": [
{
"role": "user",
"content": "What opportunities and challenges will the Chinese large model industry face in 2025?"
}
],
"max_tokens": 8192
}'Authentication
All requests require a Bearer token in the Authorization header:
Authorization: Bearer YOUR_API_KEYRequest Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| model | string | Yes | Model name. See Models for available options. |
| messages | array | Yes | A list of messages comprising the conversation |
| max_tokens | integer | Yes | Maximum tokens to generate |
| system | string or array | No | System prompt for context and instructions |
| stream | boolean | No | If true, returns Server-Sent Events |
| temperature | float | No | Controls randomness. Range: 0-2 |
| top_p | float | No | Nucleus sampling. Range: 0.1-1 |
| top_k | float | No | Top-k sampling. Range: 0-50 |
| stop_sequences | array | No | Custom sequences that stop generation |
| tools | array | No | Tool definitions for function calling |
| tool_choice | object | No | How the model should use tools (auto, any, or specific tool) |
Response
{
"id": "msg_xxx",
"type": "message",
"role": "assistant",
"content": [
{
"type": "text",
"text": "The response text..."
}
],
"model": "claude-sonnet-4-6",
"stop_reason": "end_turn",
"stop_sequence": null,
"usage": {
"input_tokens": 2095,
"output_tokens": 503
}
}Response Fields
| Field | Type | Description |
|---|---|---|
| id | string | Message identifier |
| type | string | Always “message” |
| role | string | Always “assistant” |
| content | array | Array of content blocks (text, tool_use, etc.) |
| model | string | Model that handled the request |
| stop_reason | string | Reason for stopping: end_turn, max_tokens, tool_use, refusal |
| stop_sequence | string | Matched stop sequence, if any |
| usage | object | Token usage statistics |
Error Codes
| Code | Description |
|---|---|
| 400 | Invalid request parameters |
| 401 | Invalid or missing API key |
| 404 | Model not found |
| 429 | Rate limit exceeded |
| 503/504 | Service temporarily unavailable |
Last updated on