Chat Completions

Generate an answer from a conversation, stream output, or request tool calls.

POST /v1/chat/completions

Request

Send JSON with Content-Type: application/json and Authorization: Bearer YOUR_BULKTOKEN_API_KEY. A minimal request contains model and messages. The example below waits for a complete JSON response.

curl https://bulktoken.ai/v1/chat/completions \
  -H "Authorization: Bearer $BULKTOKEN_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "model": "glm-5.3",
  "messages": [
    {
      "role": "user",
      "content": "Explain how a hash table works in three sentences."
    }
  ],
  "stream": false
}'
import os
from openai import OpenAI

client = OpenAI(
    api_key=os.environ["BULKTOKEN_API_KEY"],
    base_url="https://bulktoken.ai/v1",
    timeout=120.0,
)

response = client.chat.completions.create(
    model="glm-5.3",
    messages=[{"role": "user", "content": "Explain how a hash table works in three sentences."}],
    stream=False,
)
print(response.choices[0].message.content)
import OpenAI from "openai";

const client = new OpenAI({
  apiKey: process.env.BULKTOKEN_API_KEY,
  baseURL: "https://bulktoken.ai/v1",
  timeout: 120_000,
});

const response = await client.chat.completions.create({
  model: "glm-5.3",
  messages: [{ role: "user", content: "Explain how a hash table works in three sentences." }],
  stream: false,
});
console.log(response.choices[0].message.content);

Request parameters

Field Required Description
model Yes Exact BulkToken model ID, visible to the API key.
messages Yes Conversation messages in order. Include relevant prior turns and tool results.
stream No Use true for Server-Sent Events, false for a single JSON response.
stream_options No Streaming options; route support varies.
max_tokens No Optional completion-token budget. Accepted limits and reasoning-token accounting depend on the model and route. Do not assume the published maximum is the default.
temperature No Optional sampling control. Accepted range, default, and compatibility with reasoning mode depend on the model.
top_p No Optional nucleus sampling control. Support and interaction with temperature depend on the model.
stop No Optional stop sequence or sequences, where supported.
response_format No Model-dependent output formatting, such as {"type":"json_object"}. Strict json_schema support must be checked per model and route.
tools No Function definitions for tool calling. Your application validates and executes requested tools.

Start with model and messages. Optional controls are model-dependent; an accepted field name does not guarantee identical behavior across every model.

Conversation messages

Each message has a role and applicable content. Use user for input and retain previous assistant messages for a multi-turn conversation. System/developer instruction handling depends on the model.

content is a string for text chat. Supported media models may also accept content parts, but accepted image/video formats and limits depend on the route. For tool calls, an assistant message can have content: null and tool_calls. Return tool results with role: "tool", the matching tool_call_id, and string content. See Tool calling.

Response

Read the answer from choices[0].message.content. A tool-call response may have no answer text. Inspect finish_reason before treating a response as complete.

The following is an illustrative response, not a record of a billable request.

{
  "id": "chatcmpl-example",
  "object": "chat.completion",
  "created": 1790553600,
  "model": "glm-5.3",
  "choices": [{
    "index": 0,
    "message": {"role": "assistant", "content": "Hello!"},
    "finish_reason": "stop"
  }],
  "usage": {"prompt_tokens": 12, "completion_tokens": 8, "total_tokens": 20}
}

Finish reasons and streaming

Reason Meaning
stop The model finished the answer or reached a stop condition.
length A token budget was reached; the output can be incomplete.
tool_calls Process the requested tools and return their results.
content_filter The provider filtered output.

Other model-specific values can occur. With stream: true, process SSE chunks instead of this JSON response; see Streaming.

OpenAPI definition

Download the OpenAPI 3.1 definition for the documented inference and model-discovery endpoints. The request table above uses the same definition. For failures, see Errors and retries.