Skip to content

Anthropic Messages API reference for every model

The Anthropic Messages reference: native for Claude models, usable with GPT and Gemini, with every parameter, thinking, caching and errors.

Updated October 2, 2026
On this page

The Anthropic format. With Claude models your request is passed on in its own format, without conversion. GPT and Gemini models work here too, with the differences shown in the parameters table.

POSThttps://api.5abeer.ai/v1/messages

Authentication#

Send your key in the x-api-key header, with anthropic-version: 2023-06-01. The base URL has no /v1: the libraries add the path themselves. With the official Anthropic library, set ANTHROPIC_BASE_URL and ANTHROPIC_API_KEY; see Base URLs. Tools such as Claude Code send the key as Authorization: Bearer, and that works too.

Quick example#

curl --request POST "https://api.5abeer.ai/v1/messages" \
  --header "x-api-key: $KHABEER_API_KEY" \
  --header "Content-Type: application/json" \
  --header "anthropic-version: 2023-06-01" \
  --data '{"model":"claude-sonnet-5.5","max_tokens":512,"messages":[{"role":"user","content":"Write a product idea in one sentence."}]}'
Response
{
  "id": "msg_01Xh7",
  "type": "message",
  "role": "assistant",
  "model": "claude-sonnet-5.5",
  "content": [
    {
      "type": "text",
      "text": "Hello! How can I help you today?"
    }
  ],
  "stop_reason": "end_turn",
  "usage": {
    "input_tokens": 21,
    "output_tokens": 12
  }
}

The key is read from KHABEER_API_KEY, so it never appears in your code.

Parameters#

Each row shows what happens to the parameter for each model family: supported means we pass it to the model; ignored means the request is accepted but the parameter has no effect, so don't rely on it; rejected means the request fails. We measured these against the gateway itself.

ParameterDescriptionClaudeGPTGemini
modelstringrequiredThe model id, as in the models list.ClaudeSupportedGPTSupportedGeminiSupported
messagesarrayrequiredThe conversation with the roles user and assistant; content is text or blocks, images and tool results included.ClaudeSupportedGPTSupportedGeminiSupported
max_tokensintegerrequiredThe maximum number of output tokens.ClaudeSupportedGPTIgnoredGeminiSupported
systemstring | arraySystem instructions, as text or blocks.ClaudeSupportedGPTSupportedGeminiSupported
temperaturenumberHow random the reply is.ClaudeSupportedGPTIgnoredGeminiSupported
top_pnumberSample only from the most likely tokens.ClaudeSupportedGPTIgnoredGeminiSupported
top_kintegerSample only from a fixed number of top options.ClaudeSupportedGPTIgnoredGeminiIgnored
stop_sequencesarrayText that ends the reply.ClaudeSupportedGPTIgnoredGeminiSupported
streambooleanSend the reply as a series of events. See Streaming.ClaudeSupportedGPTSupportedGeminiSupported
toolsarrayTools with an input_schema. See Tool calling.ClaudeSupportedGPTSupportedGeminiSupported
tool_choiceobjectauto, any, none or one named tool.ClaudeSupportedGPTSupportedGeminiIgnored
thinkingobjectTurns on extended thinking with a budget_tokens budget.ClaudeSupportedGPTIgnoredGeminiIgnored
output_configobjecteffort sets how hard the model thinks: low, medium or high.ClaudeSupportedGPTSupportedGeminiIgnored
cache_controlobjectOn a content block: the cache marker. See Prompt caching.ClaudeSupportedGPTIgnoredGeminiIgnored
metadataobjectuser_id for the end user's id in your system.ClaudeSupportedGPTIgnoredGeminiIgnored

Count tokens#

POST /v1/messages/count_tokens takes the same body without max_tokens and returns input_tokens without calling the model. When counting isn't available for the model you get 404 with not_found_error, so treat the count as optional in your code.

Images in the request#

Add an image block to the content of a user message, with source of type base64 and its media_type, next to a text block, as in the image example.

Streaming#

With "stream": true the reply arrives as named events: message_start, then for each block content_block_start, content_block_delta and content_block_stop, then message_delta with the stop reason and the output usage, and message_stop. A failure mid-way arrives as an error event with the code. Details in Streaming.

Examples#

Streaming#

curl -N https://api.5abeer.ai/v1/messages \
  -H "x-api-key: $KHABEER_API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "claude-opus-5",
    "max_tokens": 512,
    "messages": [
      {
        "role": "user",
        "content": "Write a product idea in one sentence."
      }
    ],
    "stream": true
  }'
Stream events
event: message_start
data: {"type":"message_start","message":{"id":"msg_p8a01","type":"message","role":"assistant","model":"claude-opus-5","content":[],"stop_reason":null,"usage":{"input_tokens":21,"output_tokens":1}}}

event: content_block_start
data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""}}

event: content_block_delta
data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Lumen Notes: "}}

event: content_block_delta
data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"a notebook that turns voice memos "}}

event: content_block_delta
data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"into tidy to-do lists."}}

event: content_block_stop
data: {"type":"content_block_stop","index":0}

event: message_delta
data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"output_tokens":18}}

event: message_stop
data: {"type":"message_stop"}

Calling a tool#

curl https://api.5abeer.ai/v1/messages \
  -H "x-api-key: $KHABEER_API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "claude-opus-5",
    "max_tokens": 1024,
    "tools": [
      {
        "name": "get_weather",
        "description": "Get the weather for a city",
        "input_schema": {
          "type": "object",
          "properties": {
            "city": {
              "type": "string"
            }
          },
          "required": [
            "city"
          ]
        }
      }
    ],
    "tool_choice": {
      "type": "auto"
    },
    "messages": [
      {
        "role": "user",
        "content": "What is the weather in Cairo?"
      }
    ]
  }'
Response shape
{
  "id": "msg_p8a01",
  "type": "message",
  "role": "assistant",
  "model": "claude-opus-5",
  "content": [
    {
      "type": "tool_use",
      "id": "toolu_p8a01",
      "name": "get_weather",
      "input": {
        "city": "Cairo"
      }
    }
  ],
  "stop_reason": "tool_use",
  "stop_sequence": null,
  "usage": {
    "input_tokens": 21,
    "output_tokens": 18
  }
}

Extended thinking#

curl https://api.5abeer.ai/v1/messages \
  -H "x-api-key: $KHABEER_API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "claude-opus-5",
    "max_tokens": 4096,
    "thinking": {
      "type": "enabled",
      "budget_tokens": 2048
    },
    "messages": [
      {
        "role": "user",
        "content": "Plan a three-step launch for a note-taking app."
      }
    ]
  }'
Response shape
{
  "id": "msg_p8a01",
  "type": "message",
  "role": "assistant",
  "model": "claude-opus-5",
  "content": [
    {
      "type": "thinking",
      "thinking": "Three steps: audience, channel, timing.",
      "signature": "sig_p8a"
    },
    {
      "type": "text",
      "text": "Lumen Notes: a notebook that turns voice memos into tidy to-do lists."
    }
  ],
  "stop_reason": "end_turn",
  "stop_sequence": null,
  "usage": {
    "input_tokens": 21,
    "output_tokens": 18
  }
}

Reasoning effort with a GPT model#

curl https://api.5abeer.ai/v1/messages \
  -H "x-api-key: $KHABEER_API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-5.6-sol",
    "max_tokens": 1024,
    "output_config": {
      "effort": "low"
    },
    "messages": [
      {
        "role": "user",
        "content": "Write a product idea in one sentence."
      }
    ]
  }'
Response shape
{
  "id": "msg_p8a01",
  "type": "message",
  "role": "assistant",
  "model": "gpt-5.6-sol",
  "content": [
    {
      "type": "text",
      "text": "Lumen Notes: a notebook that turns voice memos into tidy to-do lists."
    }
  ],
  "stop_reason": "end_turn",
  "stop_sequence": null,
  "usage": {
    "input_tokens": 21,
    "output_tokens": 18
  }
}

Caching long instructions#

curl https://api.5abeer.ai/v1/messages \
  -H "x-api-key: $KHABEER_API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "claude-opus-5",
    "max_tokens": 512,
    "system": [
      {
        "type": "text",
        "text": "You are the support assistant for Lumen Notes. Product manual: ...",
        "cache_control": {
          "type": "ephemeral"
        }
      }
    ],
    "messages": [
      {
        "role": "user",
        "content": "How do I export a note?"
      }
    ]
  }'
Response shape
{
  "id": "msg_p8a01",
  "type": "message",
  "role": "assistant",
  "model": "claude-opus-5",
  "content": [
    {
      "type": "text",
      "text": "Lumen Notes: a notebook that turns voice memos into tidy to-do lists."
    }
  ],
  "stop_reason": "end_turn",
  "stop_sequence": null,
  "usage": {
    "input_tokens": 21,
    "output_tokens": 18
  }
}

An image with the question#

curl https://api.5abeer.ai/v1/messages \
  -H "x-api-key: $KHABEER_API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "claude-opus-5",
    "max_tokens": 512,
    "messages": [
      {
        "role": "user",
        "content": [
          {
            "type": "image",
            "source": {
              "type": "base64",
              "media_type": "image/png",
              "data": "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z8BQDwAEhQGAhKmMIQAAAABJRU5ErkJggg=="
            }
          },
          {
            "type": "text",
            "text": "What is in this image?"
          }
        ]
      }
    ]
  }'
Response shape
{
  "id": "msg_p8a01",
  "type": "message",
  "role": "assistant",
  "model": "claude-opus-5",
  "content": [
    {
      "type": "text",
      "text": "Lumen Notes: a notebook that turns voice memos into tidy to-do lists."
    }
  ],
  "stop_reason": "end_turn",
  "stop_sequence": null,
  "usage": {
    "input_tokens": 21,
    "output_tokens": 18
  }
}

Sampling settings#

curl https://api.5abeer.ai/v1/messages \
  -H "x-api-key: $KHABEER_API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gemini-3.1-pro",
    "max_tokens": 300,
    "system": "Answer in one sentence.",
    "temperature": 0.4,
    "top_p": 0.9,
    "top_k": 40,
    "stop_sequences": [
      "END"
    ],
    "metadata": {
      "user_id": "user-123"
    },
    "messages": [
      {
        "role": "user",
        "content": "Write a product idea."
      }
    ]
  }'
Response shape
{
  "id": "msg_p8a01",
  "type": "message",
  "role": "assistant",
  "model": "gemini-3.1-pro",
  "content": [
    {
      "type": "text",
      "text": "Lumen Notes: a notebook that turns voice memos into tidy to-do lists."
    }
  ],
  "stop_reason": "end_turn",
  "stop_sequence": null,
  "usage": {
    "input_tokens": 21,
    "output_tokens": 18
  }
}

The request above was run on the local test stack on 2026-10-02; the reply shows the shape, and its text is an example.

Errors#

Errors come in Anthropic's shape, "type": "error" with the details in error, except the key, balance and limit checks, which answer {"code", "message"}. The common codes are the same as for Chat Completions; the shapes and the codes raised while serving the request are in Limits and error codes.

Models for this format#

per 1M tokens

Official price from the provider's page, checked October 19, 2026.

All models and prices

GPT and Gemini models work here too; see the models list.