Skip to content

Create chat completion

OpenAI-compatible Chat Completions: shared by GPT, Gemini, GLM, Qwen, DeepSeek, Grok, Claude and other chat models.

POST/v1/chat/completions

Given a list of messages, returns the model's reply. With the OpenAI SDK, just set the Base URL to https://api.hop-base.com/v1 and use an API key from the matching group.

The table lists only the fields the gateway checks, rewrites or rejects, plus values documented on each model page; OpenAI fields not listed are forwarded as-is, with ranges per the model's official spec. The whole request body is capped at 60 MB; larger bodies return 413.

Claude models can also use this endpoint with a key from a Claude group; billing is identical to /v1/messages. When max_tokens is omitted, it defaults to 16000 for non-streaming and 64000 for streaming requests, capped at the model's output limit. Claude models do not use temperature / top_p; if sent, they are ignored without an error. n greater than 1, the legacy functions / function_call fields, and audio input return 400. Thinking blocks are not passed back between tool-call turns, so prefer /v1/messages when your client supports the Anthropic protocol. /v1/responses does not support Claude models and returns 404.

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:requiredstring

Bearer sk-…: an API key created in the console under API keys; its group must include the requested model

Body parametersJSON

Model
Fields not listed are passed through unchanged. Pick a model family to see the values and limits its docs specify.
model:requiredstring

A model ID in the current key's group; GET /v1/models is authoritative. If the group does not include the model, returns 404 model_not_found; image models such as gpt-image-* return 400 image models do not support Chat Completions, please use the Images API on this endpoint

messages:requiredarray of object

Conversation messages. Missing returns 400 missing messages field; an empty array returns 400 messages must not be an empty array

Items≥ 1

max_tokens:optionalinteger

Output cap. The gateway does not truncate or rewrite it; the limit follows the model's official spec, and values above it return an error from the model

max_completion_tokens:optionalinteger

Same as max_tokens; the newer OpenAI field name

stream:optionalboolean

true returns SSE; see Streaming events for the event format

Defaultfalse

stream_options:optionalobject

Streaming options

tools:optionalarray of object

Function tools in OpenAI function tools format, forwarded as-is.

tool_choice:optionalstring or object

auto / none / required or a specific function, forwarded as-is

temperature:optionalnumber

Sampling temperature, forwarded as-is; range per the model's official spec

top_p:optionalnumber

Nucleus sampling, forwarded as-is; range per the model's official spec

reasoning_effort:optionalstring

Reasoning effort. Values vary by model; select a model family above to see them

service_tier:optionalstring

Only priority / flex are kept; other values are removed before forwarding, without an error. priority takes effect only in groups that support it and is billed at the Fast price; elsewhere the request runs on the standard tier at the standard price. The "GPT Official Direct (Azure)" group does not support priority

Valuespriorityflex

Returns

200Success. Non-streaming returns chat.completion JSON; with stream: true it returns SSE (text/event-stream)

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

ID of this completion

object:optional"chat.completion"

Always chat.completion

created:optionalinteger

Unix seconds

model:optionalstring

Model ID actually used

choices:optionalarray of object

Candidate replies; most models return only 1

usage:optionalobject

Token usage

Errors

400Unreadable request body, missing messages, etc.
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