Skip to main content
The chat completions endpoint generates text from a list of messages. It follows the OpenAI chat completions format, so most OpenAI-compatible clients work by changing the base URL and API key.

Endpoint

Send your sk_live_ API key in the Authorization header as Bearer YOUR_API_KEY. The examples use glm-5.3-flash. For other model IDs, see Available models.

Basic request

Request parameters

Other OpenAI chat completion parameters are passed to the model, and support for them depends on the model.

Messages

Each message has a role and content:
  • system: instructions that set the assistant’s behavior. Put it first.
  • user: a message from the user.
  • assistant: an earlier reply from the model.
Each request is independent. To continue a conversation, send the full history with each request:
Every message you send counts as input tokens, so long histories cost more. Repeated prompt prefixes may be billed at the cheaper cached input rate. See How tokens are billed.

Response

The usage object reports the tokens used by the request:
  • prompt_tokens: input tokens. When present, prompt_tokens_details.cached_tokens is the part served from the prompt cache.
  • completion_tokens: output tokens, including any thinking. The thinking count is in completion_tokens_details.reasoning_tokens for glm-5.3-flash, and in a top-level reasoning_tokens field for qwen3.8-27b.
The exact fields in usage can vary by model.

Reasoning models

Reasoning models think before they answer. glm-5.3-flash and qwen3.8-27b return their thinking in a reasoning_content field, next to content in the message and in each streamed delta. The answer in content doesn’t include the thinking. Other models may not return their thinking. If a model includes its thinking in content between <think> and </think> tags, strip that section if you only want the answer. Keep these in mind when you use a reasoning model:
  • Thinking counts against max_tokens. If the model uses up max_tokens while it’s still thinking, the response ends with finish_reason set to "length" and an empty answer. Raise max_tokens and try again. Thinking length varies by prompt, and even a short question can use more than 1,000 tokens of thinking. Always set max_tokens: with glm-5.3-flash, leaving it out means a limit of 2,048, and with qwen3.8-27b it means no limit until the context window fills.
  • Thinking is billed as output tokens. It’s included in completion_tokens. See Response for where each model reports how much of it was thinking.
  • Leave earlier thinking out of the conversation history. In later requests, send only each earlier reply’s answer as the assistant message. With glm-5.3-flash, thinking sent back in reasoning_content is counted as input tokens on every turn.
  • Stop sequences also apply to the thinking. With glm-5.3-flash, if a stop sequence appears while the model is thinking, the response ends there, before any answer. Choose stop sequences that won’t appear in the reasoning.

Streaming

Set stream to true to receive tokens as they’re generated. The response is a stream of server-sent events. Each data: line holds a chunk with the next piece of text in choices[0].delta.content, and the stream ends with data: [DONE]. With glm-5.3-flash, the thinking streams first in choices[0].delta.reasoning_content. To get token counts for a streamed request, set stream_options to {"include_usage": true}. A chunk at the end of the stream then carries the usage object.
Use streaming for long generations, such as long answers or reasoning models that think for a while. A non-streaming request sends nothing until the whole response is ready, and a request that takes too long before it starts responding can time out. See Time limits.

Time limits

Each request has a time limit, including streamed requests: Non-streaming requests also time out if the response doesn’t start within about 60 seconds. For long generations, set stream to true.

Tool calling

Pass tools to let the model call functions you define. When the model decides to call one, the response has finish_reason set to "tool_calls" and a tool_calls array in the message. Each call has an id, the function name, and its arguments as a JSON string. Your code runs the function, then sends the result back so the model can answer:
  1. Add the assistant message from the response, with its tool_calls, to messages.
  2. For each call, add a message with role set to "tool", tool_call_id set to the call’s id, and the result as a string in content.
  3. Send the request again with the same tools. The model answers using the results.
Tool calling works with glm-5.3-flash, glm-5.3, and qwen3.8-27b. Support on other models depends on the model.

Structured output

Set response_format to get JSON back in content:
  • {"type": "json_schema", "json_schema": {...}} returns JSON that follows the schema you provide.
  • {"type": "json_object"} returns valid JSON without a fixed schema. Describe the keys you want in your prompt.
Structured output works with glm-5.3-flash, glm-5.3, and qwen3.8-27b. Support on other models depends on the model.

List models

GET /v1/models returns the models you can call, in the OpenAI list format. It needs your API key, like other requests.
Each entry in data has the model id to pass in the model field, and owned_by, the model’s creator:

OpenAI SDK compatibility

Point an OpenAI SDK at the Hyperbolic base URL and use your Hyperbolic API key:

Next steps

Errors

Error codes and how to handle them.

Inference overview

Pricing, billing, and access requirements.