Skip to main content
POST
/
v1
/
chat
/
completions
from cerebras.cloud.sdk import Cerebras import os client = Cerebras(api_key=os.environ.get("CEREBRAS_API_KEY")) chat_completion = client.chat.completions.create( model="gpt-oss-120b", messages=[ {"role": "user", "content": "Hello!"} ], ) print(chat_completion)
{ "id": "chatcmpl-b8d624a5-43d4-477a-8b94-61be750e2872", "choices": [ { "finish_reason": "stop", "index": 0, "message": { "role": "assistant", "content": "Hello! How can I assist you today?", "tool_calls": null }, "logprobs": null } ], "created": 1775679664, "model": "gpt-oss-120b", "object": "chat.completion", "system_fingerprint": "fp_4c26d27ac5dbffe28c72", "usage": { "prompt_tokens": 69, "completion_tokens": 45, "total_tokens": 114 } }
Parameter support can differ depending on the model used to generate the response, particularly for newer reasoning models. For details about parameters in reasoning models, refer to the Reasoning Guide.

Authorizations

Authorization
string
header
required

API key for authentication. Obtain your key from the Cerebras Cloud console and pass it as Authorization: Bearer YOUR_API_KEY.

Headers

Content-Type
enum<string>
default:application/json

The media type of the request body. Supported values: application/json, application/vnd.msgpack. Default: application/json.

Available options:
application/json,
application/vnd.msgpack
Content-Encoding
enum<string>

The compression encoding applied to the request body. When set, the request body must be gzip-compressed. Can be combined with any supported Content-Type. Supported values: gzip.

Available options:
gzip
queue_threshold
string

Controls the queue time threshold for requests using the flex or auto service tiers. Requests are preemptively rejected if the rolling average queue time exceeds this threshold. Valid range: 5020000 (milliseconds). Private Preview.

Body

application/json
messages
(System message · object | User message · object | Assistant message · object | Tool message · object | Developer message · object)[]
required

A list of messages comprising the conversation so far. Depending on the model you use, different message types (modalities) are supported, like text and images.

Developer-provided instructions the model should follow regardless of user messages.

model
string
required

The ID of the model to use for generating a response.

clear_thinking
boolean | null

Controls whether thinking content from previous conversation turns is included in the prompt context.

  • false - Thinking from all previous turns is preserved in the conversation history. Recommended for agentic workflows where reasoning from past tool-calling turns may be relevant for future tool calls.
  • true (default) - Thinking from earlier turns is excluded. Recommended for general chat conversations where reasoning from past turns is less relevant for performance.

When this parameter is not specified or set to null, the API defaults to clear_thinking: true.

Only supported on the zai-glm-4.7 model. For additional information, see Preserved thinking in the Z.ai documentation.

frequency_penalty
number | null
default:0

A number between -2.0 and 2.0. Positive values reduce the likelihood of the model repeating tokens by applying a penalty proportional to how frequently each token has already appeared in the generated output.

Required range: -2 <= x <= 2
logit_bias
object

Modify the likelihood of specified tokens appearing in the completion. Accepts a JSON object that maps tokens (specified by their token ID in the tokenizer) to an associated bias value from -100 to 100. Mathematically, the bias is added to the logits generated by the model prior to sampling. The exact effect will vary per model, but values between -1 and 1 should decrease or increase likelihood of selection; values like -100 or 100 should result in a ban or exclusive selection of the relevant token.

logprobs
boolean
default:false

Whether to return log probabilities of the output tokens.

max_completion_tokens
integer | null

The maximum number of tokens that can be generated in the completion, including reasoning tokens. The total length of input tokens and generated tokens is limited by the model's context length.

parallel_tool_calls
boolean | null
default:true

Whether to enable parallel function calling during tool use. When enabled (default), the model can request multiple tool calls simultaneously in a single response. When disabled, only one tool call is made at a time.

prediction
object

Configuration for a Predicted Output, which can greatly speed up response times when large parts of the model response are known in advance. Most common when regenerating a file with mostly minor changes.

presence_penalty
number | null
default:0

A number between -2.0 and 2.0. Positive values reduce the likelihood of the model repeating tokens that have already appeared in the output, encouraging the model to introduce new topics.

Required range: -2 <= x <= 2
prompt_cache_key
string | null

An opaque identifier that groups related requests so they reuse the same prompt cache. Requests sharing the same 'prompt_cache_key' are routed together, which increases cache hits and reduces time to first token.

Set it to a stable identifier like a conversation ID, user ID, or session ID.

Requires account-level enablement. Contact us or reach out to your account representative to request access.

Maximum string length: 1024
reasoning_effort
enum<string> | null

Controls the amount of reasoning the model performs. Supported values vary by model:

  • gpt-oss-120b: low, medium (default), high
  • zai-glm-4.7: none (disables reasoning)
  • gemma-4-31b: none (default), low, medium, high (all enable reasoning equivalently). raw and hidden reasoning formats are not supported.
Available options:
low,
medium,
high,
none
response_format
Text · object

An object that controls the format of the model response.

Setting { "type": "json_schema", ... } enables Structured Outputs, which enforces schema compliance. See Structured Outputs for details.

Setting { "type": "json_object" } enables legacy JSON mode, which ensures the model returns valid JSON but does not enforce a specific schema. To use json_object, include a system or user message specifying the desired format. json_object is not compatible with streaming — stream must be set to false.

seed
integer | null

If specified, the system will make a best effort to sample deterministically so repeated requests with the same seed and parameters return the same result. Determinism is not guaranteed.

service_tier
enum<string> | null
default:default

Controls request prioritization.

Note: This feature is in Private Preview. For access or more information, contact us or reach out to your account representative.

Available options:

  • priority - Highest priority processing (Only available for dedicated endpoints, not shared endpoints.)
  • default - Standard priority processing
  • auto - Automatically uses the highest available service tier
  • flex - Lowest priority processing

See Service Tiers for more information.

Available options:
priority,
default,
auto,
flex
stop
string | null

Up to 4 sequences where the API will stop generating further tokens. The returned text will not contain the stop sequence.

stream
boolean | null

If set to true, partial message deltas will be sent.

temperature
number | null

Sampling temperature between 0 and 2.0. Higher values (e.g. 0.8) make output more random; lower values (e.g. 0.2) make it more focused and deterministic. We recommend altering this or top_p, not both.

Required range: 0 <= x <= 2
tool_choice

Controls which (if any) tool is called by the model.

  • none — no tool is called
  • auto — (default when tools are present) the model chooses whether to call a tool
  • required — forces a tool call

A specific tool can be forced by passing an object specifying the function name.

Available options:
none,
auto,
required
tools
object[] | null

A list of tools the model may call. Use this to provide a list of functions the model may generate JSON inputs for.

Currently, only functions are supported. Specifying tools consumes prompt tokens; too many may degrade performance or hit context length limits.

top_logprobs
integer | null

An integer between 0 and 20 specifying the number of most likely tokens to return at each token position, each with an associated log probability. If using this parameter, logprobs must also be set to true.

Required range: 0 <= x <= 20
top_p
number | null

Nucleus sampling parameter. The model considers only the tokens comprising the top top_p probability mass (e.g. 0.1 means only the tokens comprising the top 10% probability mass are considered). We recommend altering this or temperature, not both.

Required range: 0 <= x <= 1
user
string | null

A unique identifier representing your end-user, which can help monitor and detect abuse.

Response

200 - application/json

Successful response

id
string

A unique identifier for the chat completion.

choices
object[]

A list of chat completion choices. Can be more than one if n is greater than 1.

created
integer

Unix timestamp (in seconds) of when the completion was created.

model
string

The model used for the chat completion.

object
enum<string>

The object type. Always chat.completion.

Available options:
chat.completion
system_fingerprint
string

A fingerprint for the model or backend used to generate the response.

service_tier
string | null

The service tier used for the request, or null if not specified.

service_tier_used
enum<string> | null

The service tier used for processing the request. Only present when service_tier is set to auto in the request.

Available options:
priority,
default,
flex
usage
object

Usage statistics for the completion request.

time_info
object

Performance timing information for the request.