Skip to content

Create message

Anthropic Messages API: the native protocol for Claude models, also available for DeepSeek, Qwen, and US-region models; the Base URL has no /v1, and the Anthropic SDK and Claude Code work directly.

POST/v1/messages

Claude models use the Anthropic protocol; DeepSeek, Qwen, and US-region (-us) models support it too, and for any other model its own page is authoritative. Set the SDK Base URL to https://api.hop-base.com (without /v1); the request path is still /v1/messages. POST /v1/messages/count_tokens is also supported.

The table lists only the parts the gateway fills in or handles specially; other Messages API fields are forwarded as-is, with ranges per Anthropic's official spec. Claude models can also be called through the OpenAI-compatible /v1/chat/completions, but this endpoint is the most complete: it preserves thinking between tool calls and supports prompt-caching controls and Anthropic-native parameters. /v1/responses does not support Claude models and returns 404 "This API path is not supported by the current platform".

Charged non-streaming responses return the actual charge for this request: the X-HopBase-Cost / X-HopBase-Cost-USD / X-HopBase-Currency headers, plus cost / cost_usd / currency in the top-level usage object of the body (existing usage fields are kept). cost_usd is the USD amount actually deducted from your balance; cost is the same charge in CNY, and currency is always CNY. Streaming (SSE) responses do not carry it; check Usage in the console. Uncharged responses, such as errors, carry neither. See Account API · Charges.

Headers

Authorization:optionalstring

Bearer sk-…; or send x-api-key: sk-… instead — either works

anthropic-version:optionalstring

Added automatically by the SDK and forwarded as-is, e.g. 2023-06-01

anthropic-beta:optionalstring

Beta feature flags, forwarded as-is

Body parametersJSON

model:requiredstring

A model ID in the current key's group (Claude, or a model that supports this protocol, such as DeepSeek or Qwen); if the group does not include the model, returns 404 model_not_found

max_tokens:optionalinteger

No gateway cap; the maximum follows the model's official spec. The official API requires it; HopBase fills in 4096 when it is missing, so long outputs are cut off at 4096 (stop_reason: "max_tokens"). Set it explicitly

Default4096

messages:requiredarray of object

In Anthropic's official format, forwarded as-is

Items≥ 1

system:optionalstring or array

System prompt, forwarded as-is

stream:optionalboolean

true returns an Anthropic SSE event stream

Defaultfalse

tools:optionalarray of object

Anthropic tool definitions (name, description, input_schema), forwarded as-is

thinking:optionalobject

Extended thinking config, forwarded as-is; values per Anthropic's official spec

temperature:optionalnumber

Forwarded as-is; range per Anthropic's official spec

Returns

200Success. Non-streaming returns message JSON; with stream: true it returns Anthropic SSE

Response headers

X-HopBase-Cost:optionalstring

The charge for this request in CNY (the same charge as X-HopBase-Cost-USD), up to 6 decimal places, such as 0.0816. Sent only when the request is charged; not sent on streaming (SSE) responses. When image generation takes longer than about 40 seconds the headers have already been sent, so read usage.cost in the body instead

X-HopBase-Cost-USD:optionalstring

The USD amount actually deducted from your balance for this request, the same amount as its usage record, up to 8 decimal places, such as 0.012; sent only together with X-HopBase-Cost

X-HopBase-Currency:optionalstring

The currency of X-HopBase-Cost, always CNY

id:optionalstring

Message ID

type:optional"message"
role:optional"assistant"
model:optionalstring

Model ID

content:optionalarray of object

Content blocks

stop_reason:optionalstring

end_turn / max_tokens / tool_use / stop_sequence

usage:optionalobject

Token usage

Errors

400Anthropic shape: {"type":"error","error":{"type":"invalid_request_error","message":"…"}}, with no code. Key-validation errors (401, 402, 403) still use the OpenAI shape
401Missing, invalid or expired API key (missing_api_key / invalid_api_key / api_key_expired)
402Balance, or key / member / department quota, exhausted (insufficient_quota)
404The model is not in this key's group (model_not_found), or the path does not belong to the group (route_not_found)
413Request body over 60 MB (request_too_large)
429Account or key concurrency cap reached (user_concurrency_limit / apikey_concurrency_limit), with Retry-After

Related