CerebrasProvider#

Connect a provider and configure retries, credentials, and transport. See the guide.

class zett_agent.providers.cerebras.CerebrasProvider(*, model, api_key, base_url=None, transport=None, temperature=None, response=False, retry=RetryOptions(base_delay=0.25, max_delay=8.0, max_retries=3), send_prompt_cache_key=None, extra_headers=None, extra_query=None, extra_body=None, timeout=TimeoutOptions(connect=5.0, first_byte=60.0, idle=600.0))[source]#

Stream a model served by Cerebras Inference.

Parameters:
  • model (str) – Cerebras model identifier, such as gpt-oss-120b, or the endpoint ID of a dedicated deployment.

  • api_key (str) – Cerebras API key.

  • base_url (str | None) – API root; None uses https://api.cerebras.ai/v1.

  • transport (httpx.AsyncBaseTransport | None) – Optional HTTPX transport for custom routing or tests.

  • temperature (float | None) – Optional sampling temperature.

  • retry (RetryOptions) – Model-owned retry/backoff policy; never restarts an emitted stream.

  • timeout (TimeoutOptions) – How long the provider may stay silent before the request is given up on. See TimeoutOptions.

  • send_prompt_cache_key (bool | None) – Declare the run’s prompt cache key on every request. Cerebras uses it to route related requests together.

  • extra_headers (Mapping[str, str] | None) – HTTP headers sent on every request after the adapter’s own.

  • extra_query (Mapping[str, str] | None) – URL query parameters sent on every request.

  • extra_body (Mapping[str, JsonValue] | None) – JSON fields merged into every request body last, so they add an option the adapter does not model, such as reasoning_format, and may override one it does.

  • response (bool)

Note

A dedicated deployment is named by an endpoint ID, so the model name cannot say which level names it takes. Give such an endpoint its level in extra_body.

Examples

Stream a model on Cerebras:

model = CerebrasProvider(model="gpt-oss-120b", api_key=os.environ["CEREBRAS_API_KEY"])
try:
    client = await create_agent(model)
    print((await client.run("Explain this function")).content)
finally:
    await model.aclose()
provider_name = 'cerebras'#

Name stored on messages this provider produced and compared before reasoning is replayed.

default_base_url: ClassVar[str | None] = 'https://api.cerebras.ai/v1'#

API root used when no base_url is given. A subclass for one service sets it; the generic class has none, so it requires base_url.

request_fields(request)[source]#

Give gpt-oss, qwen and gemma models a level they accept.

Parameters:

request (ModelRequest)

Return type:

dict[str, JsonValue]

replay_reasoning(message, payload)[source]#

Send the reasoning back as reasoning, the name Cerebras returns it under.

Parameters:
Return type:

None

async aclose()#

Close the SDK’s owned HTTP connection pool.

Return type:

None

chat_stop(finish_reason, *, has_tool_calls, refusal_text, stream_error, native_finish_reason)#

Say why the response ended. Override it for a service with finish reasons of its own.

Parameters:
  • finish_reason (str | None)

  • has_tool_calls (bool)

  • refusal_text (str)

  • stream_error (Mapping[str, JsonValue])

  • native_finish_reason (str | None)

Return type:

StopInfo

merge_replay(blocks, fragment)#

Add one streamed opaque block (ChatDelta.replay) to the ones collected so far.

The default appends. A service that streams one block in pieces overrides this to join them, and blocks is what finally becomes replay_blocks.

Parameters:
Return type:

None

native_deferred_tools = False#

See zett_agent.model.NativeDeferredToolsModel.native_deferred_tools. A provider opts in by overriding this on its class; the default keeps Responses, Chat Completions, Google, and Ollama on the withhold-and-search path.

read_delta(delta)#

Read one streamed delta.

The default reads content, refusal, tool_calls, and the first of reasoning_keys that has text. A service with fields of its own returns a ChatDelta that also carries them, usually by extending super().read_delta.

Parameters:

delta (Mapping[str, JsonValue])

Return type:

ChatDelta

read_usage(usage)#

Read the usage object of a chunk.

The default accepts every spelling of the cache and reasoning counters that the compatible services use.

Parameters:

usage (Mapping[str, JsonValue])

Return type:

ModelUsage

reasoning_keys = ('reasoning_content', 'reasoning')#

Fields of a streamed delta that carry reasoning text, in order of preference. Services differ on the name (reasoning_content and reasoning are the two in use), and reading both is harmless because only the first one that has text is used.

response = False#

Whether this adapter uses a Responses-style endpoint instead of its provider’s traditional message or chat-completions endpoint. Only the providers read it; the runtime does not.

responses_fields(request)#

Return the JSON fields this service takes for a Responses request, beyond the standard ones.

The standard ones (model, input, tools, temperature, tool_choice, reasoning, include) are set by the provider. They are merged into the request body after those fields, so a provider can replace one, such as the reasoning object. A field given in extra_body replaces one returned here.

Parameters:

request (ModelRequest)

Return type:

dict[str, JsonValue]

sends_prompt_cache_key = True#

Whether the run’s prompt cache key is sent when send_prompt_cache_key is not given. A service that rejects fields it does not know turns it off.

sends_stream_options = True#

Whether stream_options asks for a final usage chunk. A service that already sends one, and rejects fields it does not know, turns it off.

status_error(error)#

Turn an HTTP failure into the typed error the runtime reports.

The default reports a refusal the service sent as an HTTP error, a rejected credential, and everything else as ProviderHTTPError. A service that explains failures in a body of its own overrides this and falls back to super().

Parameters:

error (APIStatusError)

Return type:

ProviderError

sync(*, runtime=None)#

Return a context-managed synchronous view; optionally share a runtime.

Omitting runtime creates a new background thread for this view. Passing an existing runtime reuses its loop and leaves its shutdown to the caller. This API is for service entry points, not Extension lifecycle hooks.

Examples

Use a model or tool from a plain function:

with read_file.sync() as read:
    result = read({"file_path": "README.md"})
Parameters:

runtime (SyncRuntime | None)

Return type:

SyncObject[Self]

vendor_headers()#

Return the headers this service wants on every request.

They are sent before extra_headers, so the application can still replace one.

Return type:

dict[str, str]