Overview
Creates Anthropic-compatible messages through the unified /api/v1/messages endpoint. This API supports both streaming and non-streaming responses.
Note
When using the prompt cache, explicitly set cache_control on specific content blocks (such as text chunks) to ensure stable effectiveness. Setting it only on the top-level message may not be reliably passed through, leading to cache misses.
Note
This API differs from Create a message only in its endpoint path. That API uses the dedicated /api/anthropic/v1/messages endpoint, whereas this API uses the unified /api/v1/messages endpoint.
API details
Constraints
- You must have an API key. For more information, see Manage AI API keys.
Request path
POST https://ai-api-g.oceanbase.com/api/v1/messages
Request header
Name |
Required |
Example value |
Description |
|---|---|---|---|
| Authorization | Yes | Bearer YOUR_API_KEY | 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-sonnet-4-6 | Model name |
| max_tokens | integer | Yes | 1024 | This parameter is required by Anthropic and should always be explicitly provided. |
| messages | array[object] | Yes | [{"role": "user", "content": "Hello"}] | List of messages |
| stream | boolean | No | false | Whether to enable streaming responses. |
Response
Response parameters
Name |
Type |
Description |
|---|---|---|
| success | boolean | Whether the request was successful |
| code | string | Return code |
| message | string | Response message. |
| data | object | Response 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 'https://ai-api-g.oceanbase.com/api/v1/messages' \
--header 'Authorization: Bearer YOUR_API_KEY' \
--header 'Content-Type: application/json' \
--data '{
"model": "claude-sonnet-4-6",
"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-sonnet-4-6",
"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]
