Overview
This interface provides a compatibility layer for Anthropic Messages through the standard API endpoint, supporting both streaming and non-streaming responses. Unlike dedicated Anthropic endpoints, this interface uses the unified base path /api/v1/messages, making it suitable for scenarios where compatibility with Anthropic Messages API is needed but standard endpoints are preferred.
Note
The difference between this interface and 100.create-anthropic-message.md lies in the endpoint path. The latter uses the dedicated endpoint /api/anthropic/v1/messages, while this document uses the standard endpoint /api/v1/messages.
API details
Constraints
- The caller must have an API Key. For more information, see Manage AI API Key.
Request path
POST {BASE_URL}/api/v1/messages
Request header
Name |
Required |
Example value |
Description |
|---|---|---|---|
| Authorization | Yes | Bearer {token} | Authentication information |
| Content-Type | No | application/json | Request body format |
Request parameters
Path
None
Query
None
Body
Name |
Type |
Required |
Example value |
Description |
|---|---|---|---|---|
| model | string | Yes | claude-3-opus-20240229 | Model name |
| max_tokens | integer | Yes | 1024 | Maximum number of generated tokens |
| messages | array[object] | Yes | [{"role": "user", "content": "Hello"}] | List of messages |
| stream | boolean | No | false | Whether to enable streaming response |
Response
Response parameters
Name |
Type |
Description |
|---|---|---|
| success | boolean | Whether the request was successful |
| code | string | Return code |
| message | string | Return information |
| data | object | Business return data |
data
The structure of the returned data varies based on the value of the stream parameter in the request:
- When
stream: false, thedatafield contains the complete response object. - When
stream: true, the response is in thetext/event-streamformat, and thedatafield is not applicable.
Request example
curl --request POST '{BASE_URL}/api/v1/messages' \
--header 'Authorization: Bearer {token}' \
--header 'Content-Type: application/json' \
--data '{
"model": "claude-3-opus-20240229",
"max_tokens": 1024,
"messages": [
{
"role": "user",
"content": "Hello"
}
],
"stream": false
}'
Response example
Non-streaming response example (application/json):
{
"success": true,
"code": "200",
"message": "successful",
"data": {
"id": "msg_123456",
"model": "claude-3-opus-20240229",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "Hello! How can I assist you today?"
}
}
]
}
}
Streaming response example (text/event-stream):
data: {"id":"msg_123","object":"chat.completion.chunk","choices":[{"delta":{"content":"Hello"}}]}
data: {"id":"msg_123","object":"chat.completion.chunk","choices":[{"delta":{"content":"!"}}]}
data: [DONE]
