Skip to content

CubeLoop — a Pythonic, async-native agent harness core designed for high performance, readability, and production-grade persistence.

24.8 KB
Raw Blame
---
id: cubepi-providers
title: cubepi.providers
sidebar_position: 2
hide_table_of_contents: false
---

# `cubepi.providers`

### AssistantMessage {#assistantmessage}

_class_


[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/providers/base.py#L136)


**Attributes**

- `role`: `Literal['assistant']`
- `content`: `list[Content | ThinkingContent | ToolCall]`
- `stop_reason`: `str`
- `error_message`: `str | None`
- `usage`: `Usage | None`
- `timestamp`: `float | None`
- `provider_id`: `str`
- `model_id`: `str`
- `response_id`: `str | None`
- `metadata`: `JsonObject`
- `run_id`: `str | None`


### BaseProvider {#baseprovider}

_class_

```python
BaseProvider(self, *, provider_id: str = '')
```

Concrete base class for built-in cubepi providers.

Built-in providers (Anthropic, OpenAI, OpenAI Responses, Faux) inherit
from this class to gain the persistent listener registry used by
`cubepi.tracing` and other observers. User-defined providers should
inherit from `BaseProvider` unless they implement the full `Provider`
protocol themselves.

Concrete subclasses must implement `stream()` and call
`_fire_listeners` at three points: after the request payload is
finalized, for each `StreamEvent` pushed onto the stream, and exactly
once in a `finally` block after the stream terminates.

Per-call mutators (`StreamOptions.on_payload`,
`StreamOptions.on_response`) retain their existing single-slot
semantics and fire independently of the persistent listener registry
below.

[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/providers/base.py#L691)


**Attributes**

- `provider_id`


**Methods**

#### `model` {#baseprovider-model}

```python
model(id: str, *, api: str = '', reasoning: bool = False, context_window: int = 200000, max_tokens: int = 8192, temperature: float = 0.7, cost: ModelCost | None = None, thinking_level_map: dict[str, str | None] | None = None) -> BoundModel
```

[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/providers/base.py#L717)


#### `stream` {#baseprovider-stream}

```python
stream(model: Model, messages: list[Message], *, system_prompt: str = '', tools: list[ToolDefinition] | None = None, tool_choice: ToolChoice | None = None, options: StreamOptions | None = None) -> MessageStream
```

[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/providers/base.py#L744)


#### `generate` {#baseprovider-generate}

```python
generate(model: Model, messages: list[Message], *, system_prompt: str = '', tools: list[ToolDefinition] | None = None, tool_choice: ToolChoice | None = None, options: StreamOptions | None = None, max_output_tokens: int | None = None, temperature: float | None = None, thinking: ThinkingLevel | None = None, thinking_budgets: ThinkingBudgets | None = None) -> AssistantMessage
```

Run a single provider call and return the final assistant message.

[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/providers/base.py#L756)


#### `subscribe_request` {#baseprovider-subscribe-request}

```python
subscribe_request(cb: OnRequestCallback) -> Callable[[], None]
```

Register a persistent observer for request payloads.

Returns a detach callable that removes this specific subscription.

[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/providers/base.py#L809)


#### `subscribe_chunk` {#baseprovider-subscribe-chunk}

```python
subscribe_chunk(cb: OnChunkCallback) -> Callable[[], None]
```

Register a persistent observer for stream chunks.

Returns a detach callable.

[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/providers/base.py#L817)


#### `subscribe_response` {#baseprovider-subscribe-response}

```python
subscribe_response(cb: OnResponseBodyCallback) -> Callable[[], None]
```

Register a persistent observer for assembled responses.

Returns a detach callable.

[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/providers/base.py#L825)



### BoundModel {#boundmodel}

_class_

```python
BoundModel(self, provider: Provider, spec: Model)
```


[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/providers/base.py#L859)


**Attributes**

- `provider`: `Provider`
- `spec`: `Model`


**Methods**

#### `stream` {#boundmodel-stream}

```python
stream(messages: list[Message], *, system_prompt: str = '', tools: list[ToolDefinition] | None = None, tool_choice: ToolChoice | None = None, options: StreamOptions | None = None) -> MessageStream
```

[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/providers/base.py#L864)


#### `generate` {#boundmodel-generate}

```python
generate(messages: list[Message], *, system_prompt: str = '', tools: list[ToolDefinition] | None = None, tool_choice: ToolChoice | None = None, options: StreamOptions | None = None, max_output_tokens: int | None = None, temperature: float | None = None, thinking: ThinkingLevel | None = None, thinking_budgets: ThinkingBudgets | None = None) -> AssistantMessage
```

[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/providers/base.py#L888)


#### `generate_structured` {#boundmodel-generate-structured}

```python
generate_structured(output_type: type[BaseModelT], messages: list[Message], *, system_prompt: str = '', tool_name: str = 'structured_output', tool_description: str = 'Return the structured output', max_output_tokens: int | None = None, temperature: float | None = None, max_retries: int = 1) -> BaseModelT
```

[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/providers/base.py#L915)



### Content {#content}

_attribute_

```python
Content = TextContent | ImageContent
```


[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/providers/base.py#L118)


### ImageContent {#imagecontent}

_class_


[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/providers/base.py#L107)


**Attributes**

- `type`: `Literal['image']`
- `source`: `str`
- `media_type`: `str`


### Message {#message}

_attribute_

```python
Message = UserMessage | AssistantMessage | ToolResultMessage
```


[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/providers/base.py#L162)


### MessageStream {#messagestream}

_class_

```python
MessageStream(self)
```


[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/providers/base.py#L312)


**Methods**

#### `attach_task` {#messagestream-attach-task}

```python
attach_task(task: asyncio.Task) -> None
```

[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/providers/base.py#L320)


#### `push` {#messagestream-push}

```python
push(event: StreamEvent) -> None
```

[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/providers/base.py#L332)


#### `set_result` {#messagestream-set-result}

```python
set_result(message: AssistantMessage) -> None
```

[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/providers/base.py#L337)


#### `result` {#messagestream-result}

```python
result() -> AssistantMessage
```

Return the final assistant message.

Blocks not just on the result future, but also on the producer
task's completion — the producer's `finally` block runs
`_fire_response_listeners` (after `set_result`), so
without waiting for the task, callers under `asyncio.run`
teardown could exit before async response listeners have run.
Producer exceptions are NOT re-raised here; they were already
surfaced via the result future or the stream's error events.

[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/providers/base.py#L350)



### Model {#model}

_class_


[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/providers/base.py#L86)


**Attributes**

- `id`: `str`
- `provider_id`: `str`
- `api`: `str`
- `reasoning`: `bool`
- `context_window`: `int`
- `max_tokens`: `int`
- `temperature`: `float`
- `cost`: `ModelCost | None`
- `thinking_level_map`: `dict[str, str | None] | None`


### ModelCost {#modelcost}

_class_


[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/providers/base.py#L72)


**Attributes**

- `input`: `float`
- `output`: `float`
- `cache_read`: `float`
- `cache_write`: `float`


### OnChunkCallback {#onchunkcallback}

_attribute_

```python
OnChunkCallback = Callable[['StreamEvent', Model], Awaitable[None] | None]
```

Persistent observer. Fires for every StreamEvent pushed onto the stream
(start, text_delta, thinking_delta, toolcall_delta, done, error, ...).
Heavy listeners should early-return on irrelevant event types — this hook
fires hot. Return value is ignored.

[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/providers/base.py#L404)


### OnPayloadCallback {#onpayloadcallback}

_attribute_

```python
OnPayloadCallback = Callable[[dict, Model], Awaitable[dict | None] | dict | None]
```

Optional callback for inspecting/replacing provider payloads before sending.
Return a dict to replace the payload, or None to keep unchanged.

[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/providers/base.py#L391)


### OnRequestCallback {#onrequestcallback}

_attribute_

```python
OnRequestCallback = Callable[[dict, Model], Awaitable[None] | None]
```

Persistent observer. Fires just before HTTP send, after any per-call
`StreamOptions.on_payload` mutation has been applied. Receives the final
wire payload dict and the Model. Return value is ignored.

[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/providers/base.py#L399)


### OnResponseBodyCallback {#onresponsebodycallback}

_attribute_

```python
OnResponseBodyCallback = Callable[[dict | None, Model, BaseException | None], Awaitable[None] | None]
```

Persistent observer. Fires exactly once per `stream()` call, in a
finally block, after the stream terminates.

- body: assembled provider response as a dict (same shape a non-streaming
  call to the provider would have returned), or None if the stream failed
  before a response could be assembled.
- exc: the exception that ended the stream (including
  `asyncio.CancelledError`), or None on normal completion.
Return value is ignored.

[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/providers/base.py#L410)


### OnResponseCallback {#onresponsecallback}

_attribute_

```python
OnResponseCallback = Callable[['ProviderResponse', Model], Awaitable[None] | None]
```

Optional callback invoked after an HTTP response is received.

[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/providers/base.py#L395)


### Provider {#provider}

_class_


[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/providers/base.py#L662)


**Methods**

#### `stream` {#provider-stream}

```python
stream(model: Model, messages: list[Message], *, system_prompt: str = '', tools: list[ToolDefinition] | None = None, tool_choice: ToolChoice | None = None, options: StreamOptions | None = None) -> MessageStream
```

[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/providers/base.py#L664)


#### `generate` {#provider-generate}

```python
generate(model: Model, messages: list[Message], *, system_prompt: str = '', tools: list[ToolDefinition] | None = None, tool_choice: ToolChoice | None = None, options: StreamOptions | None = None, max_output_tokens: int | None = None, temperature: float | None = None, thinking: ThinkingLevel | None = None, thinking_budgets: ThinkingBudgets | None = None) -> AssistantMessage
```

[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/providers/base.py#L675)



### ProviderResponse {#providerresponse}

_class_

```python
ProviderResponse(self, status: int, headers: dict[str, str] = dict())
```

HTTP response metadata exposed to on_response callbacks.

[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/providers/base.py#L383)


**Attributes**

- `status`: `int`
- `headers`: `dict[str, str]`


### StreamEvent {#streamevent}

_class_


[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/providers/base.py#L260)


**Attributes**

- `type`: `Literal['start', 'text_start', 'text_delta', 'text_end', 'thinking_start', 'thinking_delta', 'thinking_end', 'toolcall_start', 'toolcall_delta', 'toolcall_end', 'done', 'error']`
- `content_index`: `int | None`
- `delta`: `str | None`
- `partial`: `AssistantMessage | None`
- `error_message`: `str | None`


### StreamOptions {#streamoptions}

_class_

Options bag for Provider.stream(), transparent to the agent loop.

[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/providers/base.py#L623)


**Attributes**

- `model_config`
- `thinking`: `ThinkingLevel`
- `thinking_budgets`: `ThinkingBudgets | None`
- `signal`: `asyncio.Event | None`
- `on_payload`: `OnPayloadCallback | None`
- `on_response`: `OnResponseCallback | None`


### TextContent {#textcontent}

_class_


[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/providers/base.py#L102)


**Attributes**

- `type`: `Literal['text']`
- `text`: `str`


### ThinkingBudgets {#thinkingbudgets}

_class_

Token budgets for each thinking level.

[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/providers/base.py#L30)


**Attributes**

- `low`: `int`
- `medium`: `int`
- `high`: `int`


### ThinkingContent {#thinkingcontent}

_class_


[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/providers/base.py#L113)


**Attributes**

- `type`: `Literal['thinking']`
- `thinking`: `str`


### ThinkingLevel {#thinkinglevel}

_attribute_

```python
ThinkingLevel = Literal['off', 'low', 'medium', 'high', 'xhigh']
```


[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/providers/base.py#L25)


### ToolCall {#toolcall}

_class_


[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/providers/base.py#L121)


**Attributes**

- `type`: `Literal['tool_call']`
- `id`: `str`
- `name`: `str`
- `arguments`: `JsonObject`


### ToolDefinition {#tooldefinition}

_class_


[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/providers/base.py#L254)


**Attributes**

- `name`: `str`
- `description`: `str`
- `parameters`: `JsonObject`


### ToolResultMessage {#toolresultmessage}

_class_


[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/providers/base.py#L150)


**Attributes**

- `role`: `Literal['tool_result']`
- `tool_call_id`: `str`
- `tool_name`: `str`
- `content`: `list[Content]`
- `details`: `StructuredValue`
- `is_error`: `bool`
- `timestamp`: `float | None`
- `metadata`: `JsonObject`
- `run_id`: `str | None`


### Usage {#usage}

_class_


[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/providers/base.py#L79)


**Attributes**

- `input_tokens`: `int`
- `output_tokens`: `int`
- `cache_read_tokens`: `int`
- `cache_write_tokens`: `int`


### UserMessage {#usermessage}

_class_


[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/providers/base.py#L128)


**Attributes**

- `role`: `Literal['user']`
- `content`: `list[Content]`
- `timestamp`: `float | None`
- `metadata`: `JsonObject`
- `run_id`: `str | None`


### is_synthetic_message {#is-synthetic-message}

_function_

```python
is_synthetic_message(message: Message) -> bool
```

True if `message` was injected by the framework rather than a human.

[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/providers/base.py#L197)


### synthetic_user_message {#synthetic-user-message}

_function_

```python
synthetic_user_message(text: str, *, source: str) -> UserMessage
```

Build a user-role message injected by the framework, not typed by a human.

All injected user-role messages MUST be created through this factory so
downstream consumers can branch on a single marker
(`metadata["synthetic"] is True`). `source` (e.g. `"todo_guard"`,
`"goal_continuation"`) is for tracing/debugging only — UI behavior
should never depend on it.

[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/providers/base.py#L179)


### adjust_max_tokens_for_thinking {#adjust-max-tokens-for-thinking}

_function_

```python
adjust_max_tokens_for_thinking(base_max_tokens: int, model_max_tokens: int, reasoning_level: ThinkingLevel, custom_budgets: ThinkingBudgets | None = None) -> tuple[int, int]
```

Adjust max_tokens to reserve space for a thinking budget.

Given a base max_tokens (the desired output capacity), increases it to
accommodate the thinking budget while respecting the model's hard cap.
If the model cap is too small to fit both, the thinking budget is reduced
to leave at least `min_output_tokens` (1024) for output.


**Returns**

- A `(max_tokens, thinking_budget)` tuple.

[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/providers/base.py#L38)


### chain_providers {#chain-providers}

_function_

```python
chain_providers(model: object) -> list['BaseProvider']
```

Return the unique BaseProvider instances backing a bound model.

Walks a model's `chain` (FallbackBoundModel-like) or its single
`.provider` (plain BoundModel-like). Uses duck typing on `.chain` to
avoid importing `cubepi.providers.fallback` into this base module —
`fallback` already depends on `base`, so the reverse import would
cycle.

For `FallbackBoundModel`-like inputs, iterates the chain and dedupes
providers by identity. Chain entries whose `.provider` isn't a
`BaseProvider` are logged at WARNING via stdlib `logging` and
skipped — tracing / metrics need the `subscribe_request` /
`subscribe_chunk` / `subscribe_response` interface that only
`BaseProvider` exposes. (cubepi does not depend on loguru; hosts that
use it can intercept stdlib logging.)

For plain bound models, returns `[model.provider]` if it is a
`BaseProvider`. For `None` or any other input, returns `[]`.

Used by `cubepi.tracing.recorder.Recorder.attach` and
`cubepi.tracing.meter.Meter.attach` to subscribe to every leg of a
fallback chain so post-failover provider events land in the trace /
metric stream.

[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/providers/base.py#L989)


### collect_agent_providers {#collect-agent-providers}

_function_

```python
collect_agent_providers(agent: Any) -> list['BaseProvider']
```

Return the unique BaseProvider instances backing an agent.

Walks `agent._model` via [`chain_providers`](./cubepi-providers#chain-providers) and falls back to a
public `provider` attribute on the agent for legacy code paths. Used
by both `cubepi.tracing.recorder.Recorder.attach` and
`cubepi.tracing.meter.Meter.attach` to dedupe the prelude that
finds providers to subscribe to.

[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/providers/base.py#L1040)


### FauxProvider {#fauxprovider}

_class_

```python
FauxProvider(self, *, tokens_per_second: float | None = None, token_size_min: int = 3, token_size_max: int = 5, provider_id: str = '')
```


[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/providers/faux.py#L157)


**Attributes**

- `call_count`
- `pending_response_count`: `int`
- `prompt_cache`: `dict[str, str]` — Read-only access to the prompt cache for test assertions.


**Methods**

#### `set_responses` {#fauxprovider-set-responses}

```python
set_responses(responses: list[FauxResponseStep]) -> None
```

[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/providers/faux.py#L216)


#### `append_responses` {#fauxprovider-append-responses}

```python
append_responses(responses: list[FauxResponseStep]) -> None
```

[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/providers/faux.py#L219)


#### `clear_prompt_cache` {#fauxprovider-clear-prompt-cache}

```python
clear_prompt_cache() -> None
```

Clear the prompt cache, useful between test scenarios.

[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/providers/faux.py#L226)


#### `stream` {#fauxprovider-stream}

```python
stream(model: Model, messages: list[Message], *, system_prompt: str = '', tools: list[ToolDefinition] | None = None, tool_choice: ToolChoice | None = None, options: StreamOptions | None = None) -> MessageStream
```

[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/providers/faux.py#L268)



### faux_assistant_message {#faux-assistant-message}

_function_

```python
faux_assistant_message(content: str | FauxContentBlock | list[FauxContentBlock], *, stop_reason: str = 'stop', error_message: str | None = None) -> AssistantMessage
```


[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/providers/faux.py#L65)


### faux_text {#faux-text}

_function_

```python
faux_text(text: str) -> TextContent
```


[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/providers/faux.py#L48)


### faux_thinking {#faux-thinking}

_function_

```python
faux_thinking(thinking: str) -> ThinkingContent
```


[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/providers/faux.py#L52)


### faux_tool_call {#faux-tool-call}

_function_

```python
faux_tool_call(name: str, arguments: dict[str, Any], *, id: str | None = None) -> ToolCall
```


[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/providers/faux.py#L56)


### DEFAULT_TRIGGER_ERRORS {#default-trigger-errors}

_attribute_

```python
DEFAULT_TRIGGER_ERRORS: frozenset[type[ProviderError]] = frozenset({RateLimited, ProviderUnavailable, ContextLengthExceeded})
```


[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/providers/fallback.py#L36)


### FallbackBoundModel {#fallbackboundmodel}

_class_

```python
FallbackBoundModel(self, chain: tuple[BoundModel, ...], trigger_errors: frozenset[type[ProviderError]] = DEFAULT_TRIGGER_ERRORS, on_failover: Callable[[BoundModel, BoundModel | None, BaseException | str], Awaitable[None] | None] | None = None)
```

Ordered chain of BoundModels — tries each in turn on retriable errors.

chain[0] is the primary model. On a trigger_errors exception or a first-event
error from stream(), the next model in the chain is tried transparently.
For generate(), an error AssistantMessage (stop_reason="error") also triggers
failover. Mid-stream errors (after the first non-error event) are forwarded
as-is.

provider and spec proxy chain[0] so tracing/billing code that reads
agent._model.provider / agent._model.spec continues to work unchanged.

Tracer / Meter coverage: Recorder.attach() and Meter.attach() detect
FallbackBoundModel and subscribe to every unique BaseProvider in the
chain (via chain_providers() below), so post-failover chat spans and
provider metrics land in the trace / metric stream like primary-leg
calls do.

[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/providers/fallback.py#L41)


**Attributes**

- `chain`: `tuple[BoundModel, ...]`
- `trigger_errors`: `frozenset[type[ProviderError]]`
- `on_failover`: `Callable[[BoundModel, BoundModel | None, BaseException | str], Awaitable[None] | None] | None`
- `provider`: `Provider`
- `spec`: `Model`


**Methods**

#### `stream` {#fallbackboundmodel-stream}

```python
stream(messages: list[Message], *, system_prompt: str = '', tools: list[ToolDefinition] | None = None, tool_choice: ToolChoice | None = None, options: StreamOptions | None = None) -> MessageStream
```

[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/providers/fallback.py#L120)


#### `generate` {#fallbackboundmodel-generate}

```python
generate(messages: list[Message], *, system_prompt: str = '', tools: list[ToolDefinition] | None = None, tool_choice: ToolChoice | None = None, options: StreamOptions | None = None, max_output_tokens: int | None = None, temperature: float | None = None, thinking: ThinkingLevel | None = None, thinking_budgets: ThinkingBudgets | None = None) -> AssistantMessage
```

[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/providers/fallback.py#L196)



### THINKING_LEVELS {#thinking-levels}

_attribute_

```python
THINKING_LEVELS: list[ThinkingLevel] = ['off', 'low', 'medium', 'high', 'xhigh']
```


[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/providers/models.py#L12)


### clamp_thinking_level {#clamp-thinking-level}

_function_

```python
clamp_thinking_level(model: Model, level: ThinkingLevel) -> ThinkingLevel
```

Clamp *level* to the nearest supported level for *model*.

If *level* is already supported, return it unchanged.  Otherwise search
upward first (higher intensity), then downward, through the ordered level
list to find the closest available level.

[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/providers/models.py#L53)


### get_supported_thinking_levels {#get-supported-thinking-levels}

_function_

```python
get_supported_thinking_levels(model: Model) -> list[ThinkingLevel]
```

Return the thinking levels supported by *model*.

* Non-reasoning models only support `["off"]`.
* For reasoning models, levels are filtered through the model's
  `thinking_level_map`.  A level mapped to `None` is unsupported.
  `"xhigh"` is only included when it has an explicit (non-None) mapping.
  All other levels are included by default when the map omits them.

[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/providers/models.py#L21)


### models_are_equal {#models-are-equal}

_function_

```python
models_are_equal(a: Model | None, b: Model | None) -> bool
```

Return `True` if *a* and *b* refer to the same model.

Comparison is by `id` and `provider_id`.  Returns `False` when either
argument is `None`.

[source](https://github.com/cubeplexai/cubepi/blob/main/cubepi/providers/models.py#L86)



<!-- GENERATED by build_api_reference.py — DO NOT EDIT -->