Skip to content
中文

Messages - Official Anthropic Format

Method: POSTEndpoint: /v1/messages

This endpoint calls available Claude / LLM models with the Anthropic Messages format. The full request URL is {BaseURL}/v1/messages. For Base URL and API key setup, see Get Base URL and API Key.

Minimal Text Request

Request Parameters

Header Parameters

text
Authorization
string
Required
Default Value:
Bearer YOUR_API_KEY
text
Content-Type
string
Required
Default Value:
application/json
text
anthropic-version
string
Optional
Example:
2023-06-01

Body Parameters application/json

text
object
Example
{
  "model": "claude-3-5-sonnet-20240620",
  "max_tokens": 1024,
  "messages": [
    {
      "role": "user",
      "content": [
        {
          "type": "text",
          "text": "Hello, Claude format."
        }
      ]
    }
  ]
}

Common fields:

FieldTypeRequiredDescription
modelstringYesModel name. Check available models with List Models.
max_tokensnumberYesMaximum output tokens.
messagesarrayYesMessage array in Anthropic Messages format.
messages[].rolestringYesUsually user or assistant.
messages[].contentarrayYesContent block array. Text blocks use { "type": "text", "text": "..." }.
streambooleanNoWhether to use streaming, depending on upstream model support.

Example Request

Shell

bash
curl --location --request POST '{BaseURL}/v1/messages' \
--header 'Authorization: Bearer YOUR_API_KEY' \
--header 'Content-Type: application/json' \
--data-raw '{
  "model": "claude-3-5-sonnet-20240620",
  "max_tokens": 1024,
  "messages": [
    {
      "role": "user",
      "content": [
        {
          "type": "text",
          "text": "Hello, Claude format."
        }
      ]
    }
  ]
}'

Image Requests

Image understanding uses the same /v1/messages endpoint. Add an image content block to content. See Messages - Vision for an image payload example.

Migration Notes

  • If you previously called the official Anthropic API, you usually only need to replace the Base URL and API key, then confirm that the model name is available to your account.
  • If you previously called OpenAI Chat Completions, change the endpoint from /v1/chat/completions to /v1/messages and convert message content into Anthropic content blocks.
  • Do not expose API keys in public frontend code, logs, screenshots, or GitHub.

Response

🟢 200 Success

Content Type: application/json

Response Schema

text
object

Example

json
{
  "id": "msg_xxx",
  "type": "message",
  "role": "assistant",
  "content": [
    {
      "type": "text",
      "text": "Hello. How can I help?"
    }
  ],
  "model": "claude-3-5-sonnet-20240620",
  "stop_reason": "end_turn",
  "usage": {
    "input_tokens": 12,
    "output_tokens": 8
  }
}