Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions sdk/api-reference/openhands.sdk.llm.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@
---


## Import shortcuts

`TokenUsage` is part of the public LLM metrics surface and can be imported from either `openhands.sdk.llm` or the top-level `openhands.sdk` package.

```python
from openhands.sdk.llm import TokenUsage
# or
from openhands.sdk import TokenUsage
```


### class CredentialStore

Bases: `object`
Expand Down Expand Up @@ -40,7 +51,7 @@
Get stored credentials for a vendor.

* Parameters:
`vendor` – The vendor/provider name (e.g., ‘openai’)

Check warning on line 54 in sdk/api-reference/openhands.sdk.llm.mdx

View check run for this annotation

Mintlify / Mintlify Validation (allhandsai) - vale-spellcheck

sdk/api-reference/openhands.sdk.llm.mdx#L54

Did you really mean 'openai'?
* Returns:
OAuthCredentials if found and valid, None otherwise

Expand Down Expand Up @@ -75,7 +86,7 @@

#### Methods

#### model_config = (configuration object)

Check warning on line 89 in sdk/api-reference/openhands.sdk.llm.mdx

View check run for this annotation

Mintlify / Mintlify Validation (allhandsai) - vale-spellcheck

sdk/api-reference/openhands.sdk.llm.mdx#L89

Did you really mean 'model_config'?

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

Expand All @@ -90,7 +101,7 @@
Language model interface for OpenHands agents.

The LLM class provides a unified interface for interacting with various
language models through the litellm library. It handles model configuration,

Check warning on line 104 in sdk/api-reference/openhands.sdk.llm.mdx

View check run for this annotation

Mintlify / Mintlify Validation (allhandsai) - vale-spellcheck

sdk/api-reference/openhands.sdk.llm.mdx#L104

Did you really mean 'litellm'?
API authentication,
retry logic, and tool calling capabilities.

Expand Down Expand Up @@ -159,7 +170,7 @@
- `openrouter_site_url`: str
- `output_cost_per_token`: float | None
- `prompt_cache_retention`: str | None
- `reasoning_effort`: Literal['low', 'medium', 'high', 'xhigh', 'none'] | None

Check warning on line 173 in sdk/api-reference/openhands.sdk.llm.mdx

View check run for this annotation

Mintlify / Mintlify Validation (allhandsai) - vale-spellcheck

sdk/api-reference/openhands.sdk.llm.mdx#L173

Did you really mean 'xhigh'?
- `reasoning_summary`: Literal['auto', 'concise', 'detailed'] | None
- `retry_listener`: SkipJsonSchema[Callable[[int, int, BaseException | None], None] | None]
- `retry_max_wait`: int
Expand Down Expand Up @@ -191,15 +202,15 @@
* `messages` – List of conversation messages
* `tools` – Optional list of tools available to the model
* `_return_metrics` – Whether to return usage metrics
* `add_security_risk_prediction` – Add security_risk field to tool schemas

Check warning on line 205 in sdk/api-reference/openhands.sdk.llm.mdx

View check run for this annotation

Mintlify / Mintlify Validation (allhandsai) - vale-spellcheck

sdk/api-reference/openhands.sdk.llm.mdx#L205

Did you really mean 'security_risk'?
* `on_token` – Optional callback for streaming tokens
kwargs* – Additional arguments passed to the LLM API
* Returns:
LLMResponse containing the model’s response and metadata.

Check warning on line 209 in sdk/api-reference/openhands.sdk.llm.mdx

View check run for this annotation

Mintlify / Mintlify Validation (allhandsai) - vale-spellcheck

sdk/api-reference/openhands.sdk.llm.mdx#L209

Did you really mean 'LLMResponse'?

#### NOTE
Summary field is always added to tool schemas for transparency and
explainability of agent actions.

Check warning on line 213 in sdk/api-reference/openhands.sdk.llm.mdx

View check run for this annotation

Mintlify / Mintlify Validation (allhandsai) - vale-spellcheck

sdk/api-reference/openhands.sdk.llm.mdx#L213

Did you really mean 'explainability'?

* Raises:
`ValueError` – If streaming is requested (not supported).
Expand All @@ -212,11 +223,11 @@

Prepare (instructions, input[]) for the OpenAI Responses API.

- Skips prompt caching flags and string serializer concerns

Check warning on line 226 in sdk/api-reference/openhands.sdk.llm.mdx

View check run for this annotation

Mintlify / Mintlify Validation (allhandsai) - vale-spellcheck

sdk/api-reference/openhands.sdk.llm.mdx#L226

Did you really mean 'serializer'?
- Uses Message.to_responses_value to get either instructions (system)
or input items (others)
- Concatenates system instructions into a single instructions string
- For subscription mode, system prompts are prepended to user content

Check warning on line 230 in sdk/api-reference/openhands.sdk.llm.mdx

View check run for this annotation

Mintlify / Mintlify Validation (allhandsai) - vale-spellcheck

sdk/api-reference/openhands.sdk.llm.mdx#L230

Did you really mean 'prepended'?

#### get_token_count()

Expand All @@ -230,9 +241,9 @@
* Return type:
boolean

#### classmethod load_from_env()

Check warning on line 244 in sdk/api-reference/openhands.sdk.llm.mdx

View check run for this annotation

Mintlify / Mintlify Validation (allhandsai) - vale-spellcheck

sdk/api-reference/openhands.sdk.llm.mdx#L244

Did you really mean 'classmethod'?

#### classmethod load_from_json()

Check warning on line 246 in sdk/api-reference/openhands.sdk.llm.mdx

View check run for this annotation

Mintlify / Mintlify Validation (allhandsai) - vale-spellcheck

sdk/api-reference/openhands.sdk.llm.mdx#L246

Did you really mean 'classmethod'?

#### model_post_init()

Expand All @@ -248,9 +259,9 @@

Reset metrics and telemetry to fresh instances.

This is used by the LLMRegistry to ensure each registered LLM has

Check warning on line 262 in sdk/api-reference/openhands.sdk.llm.mdx

View check run for this annotation

Mintlify / Mintlify Validation (allhandsai) - vale-spellcheck

sdk/api-reference/openhands.sdk.llm.mdx#L262

Did you really mean 'LLMRegistry'?
independent metrics, preventing metrics from being shared between
LLMs that were created via model_copy().

Check warning on line 264 in sdk/api-reference/openhands.sdk.llm.mdx

View check run for this annotation

Mintlify / Mintlify Validation (allhandsai) - vale-spellcheck

sdk/api-reference/openhands.sdk.llm.mdx#L264

Did you really mean 'LLMs'?

When an LLM is copied (e.g., to create a condenser LLM from an agent LLM),
Pydantic’s model_copy() does a shallow copy of private attributes by default,
Expand All @@ -262,7 +273,7 @@

Alternative invocation path using OpenAI Responses API via LiteLLM.

Maps Message[] -> (instructions, input[]) and returns LLMResponse.

Check warning on line 276 in sdk/api-reference/openhands.sdk.llm.mdx

View check run for this annotation

Mintlify / Mintlify Validation (allhandsai) - vale-spellcheck

sdk/api-reference/openhands.sdk.llm.mdx#L276

Did you really mean 'LLMResponse'?

* Parameters:
* `messages` – List of conversation messages
Expand All @@ -270,17 +281,17 @@
* `include` – Optional list of fields to include in response
* `store` – Whether to store the conversation
* `_return_metrics` – Whether to return usage metrics
* `add_security_risk_prediction` – Add security_risk field to tool schemas

Check warning on line 284 in sdk/api-reference/openhands.sdk.llm.mdx

View check run for this annotation

Mintlify / Mintlify Validation (allhandsai) - vale-spellcheck

sdk/api-reference/openhands.sdk.llm.mdx#L284

Did you really mean 'security_risk'?
* `on_token` – Optional callback for streaming deltas
kwargs* – Additional arguments passed to the API

#### NOTE
Summary field is always added to tool schemas for transparency and
explainability of agent actions.

Check warning on line 290 in sdk/api-reference/openhands.sdk.llm.mdx

View check run for this annotation

Mintlify / Mintlify Validation (allhandsai) - vale-spellcheck

sdk/api-reference/openhands.sdk.llm.mdx#L290

Did you really mean 'explainability'?

#### restore_metrics()

#### classmethod subscription_login()

Check warning on line 294 in sdk/api-reference/openhands.sdk.llm.mdx

View check run for this annotation

Mintlify / Mintlify Validation (allhandsai) - vale-spellcheck

sdk/api-reference/openhands.sdk.llm.mdx#L294

Did you really mean 'classmethod'?

Authenticate with a subscription service and return an LLM instance.

Expand All @@ -290,7 +301,7 @@
the OAuth login flow.

Currently supported vendors:
- “openai”: ChatGPT Plus/Pro subscription for Codex models

Check warning on line 304 in sdk/api-reference/openhands.sdk.llm.mdx

View check run for this annotation

Mintlify / Mintlify Validation (allhandsai) - vale-spellcheck

sdk/api-reference/openhands.sdk.llm.mdx#L304

Did you really mean 'openai'?

Supported OpenAI models:
- gpt-5.1-codex-max
Expand All @@ -299,7 +310,7 @@
- gpt-5.2-codex

* Parameters:
* `vendor` – The vendor/provider. Currently only “openai” is supported.

Check warning on line 313 in sdk/api-reference/openhands.sdk.llm.mdx

View check run for this annotation

Mintlify / Mintlify Validation (allhandsai) - vale-spellcheck

sdk/api-reference/openhands.sdk.llm.mdx#L313

Did you really mean 'openai'?
* `model` – The model to use. Must be supported by the vendor’s
subscription service.
* `force_login` – If True, always perform a fresh login even if valid
Expand Down Expand Up @@ -380,17 +391,17 @@
* Raises:
`TimeoutError` – If the lock cannot be acquired.

### class LLMRegistry

Check warning on line 394 in sdk/api-reference/openhands.sdk.llm.mdx

View check run for this annotation

Mintlify / Mintlify Validation (allhandsai) - vale-spellcheck

sdk/api-reference/openhands.sdk.llm.mdx#L394

Did you really mean 'LLMRegistry'?

Bases: `object`

A minimal LLM registry for managing LLM instances by usage ID.

This registry provides a simple way to manage multiple LLM instances,
avoiding the need to recreate LLMs with the same configuration.

Check warning on line 401 in sdk/api-reference/openhands.sdk.llm.mdx

View check run for this annotation

Mintlify / Mintlify Validation (allhandsai) - vale-spellcheck

sdk/api-reference/openhands.sdk.llm.mdx#L401

Did you really mean 'LLMs'?

The registry also ensures that each registered LLM has independent metrics,
preventing metrics from being shared between LLMs that were created via

Check warning on line 404 in sdk/api-reference/openhands.sdk.llm.mdx

View check run for this annotation

Mintlify / Mintlify Validation (allhandsai) - vale-spellcheck

sdk/api-reference/openhands.sdk.llm.mdx#L404

Did you really mean 'LLMs'?
model_copy(). This is important for scenarios like creating a condenser LLM
from an agent LLM, where each should track its own usage independently.

Expand Down Expand Up @@ -435,7 +446,7 @@
* Returns:
The LLM instance.
* Raises:
`KeyError` – If usage_id is not found in the registry.

Check warning on line 449 in sdk/api-reference/openhands.sdk.llm.mdx

View check run for this annotation

Mintlify / Mintlify Validation (allhandsai) - vale-spellcheck

sdk/api-reference/openhands.sdk.llm.mdx#L449

Did you really mean 'usage_id'?

#### list_usage_ids()

Expand All @@ -453,9 +464,9 @@
Subscribe to registry events.

* Parameters:
`callback` – Function to call when LLMs are created or updated.

Check warning on line 467 in sdk/api-reference/openhands.sdk.llm.mdx

View check run for this annotation

Mintlify / Mintlify Validation (allhandsai) - vale-spellcheck

sdk/api-reference/openhands.sdk.llm.mdx#L467

Did you really mean 'LLMs'?

### class LLMResponse

Check warning on line 469 in sdk/api-reference/openhands.sdk.llm.mdx

View check run for this annotation

Mintlify / Mintlify Validation (allhandsai) - vale-spellcheck

sdk/api-reference/openhands.sdk.llm.mdx#L469

Did you really mean 'LLMResponse'?

Bases: `BaseModel`

Expand Down Expand Up @@ -497,7 +508,7 @@
* Type:
[openhands.sdk.llm.utils.metrics.MetricsSnapshot](#class-metricssnapshot)

#### raw_response

Check warning on line 511 in sdk/api-reference/openhands.sdk.llm.mdx

View check run for this annotation

Mintlify / Mintlify Validation (allhandsai) - vale-spellcheck

sdk/api-reference/openhands.sdk.llm.mdx#L511

Did you really mean 'raw_response'?

The original LiteLLM response (ModelResponse or
ResponsesAPIResponse) for internal use
Expand Down Expand Up @@ -526,21 +537,21 @@

#### Methods

#### classmethod from_llm_chat_message()

Check warning on line 540 in sdk/api-reference/openhands.sdk.llm.mdx

View check run for this annotation

Mintlify / Mintlify Validation (allhandsai) - vale-spellcheck

sdk/api-reference/openhands.sdk.llm.mdx#L540

Did you really mean 'classmethod'?

Convert a LiteLLMMessage (Chat Completions) to our Message class.

Provider-agnostic mapping for reasoning:
- Prefer message.reasoning_content if present (LiteLLM normalized field)
- Extract thinking_blocks from content array (Anthropic-specific)

Check warning on line 546 in sdk/api-reference/openhands.sdk.llm.mdx

View check run for this annotation

Mintlify / Mintlify Validation (allhandsai) - vale-spellcheck

sdk/api-reference/openhands.sdk.llm.mdx#L546

Did you really mean 'thinking_blocks'?

#### classmethod from_llm_responses_output()

Check warning on line 548 in sdk/api-reference/openhands.sdk.llm.mdx

View check run for this annotation

Mintlify / Mintlify Validation (allhandsai) - vale-spellcheck

sdk/api-reference/openhands.sdk.llm.mdx#L548

Did you really mean 'classmethod'?

Convert OpenAI Responses API output items into a single assistant Message.

Policy (non-stream):
- Collect assistant text by concatenating output_text parts from message items

Check warning on line 553 in sdk/api-reference/openhands.sdk.llm.mdx

View check run for this annotation

Mintlify / Mintlify Validation (allhandsai) - vale-spellcheck

sdk/api-reference/openhands.sdk.llm.mdx#L553

Did you really mean 'output_text'?
- Normalize function_call items to MessageToolCall list

Check warning on line 554 in sdk/api-reference/openhands.sdk.llm.mdx

View check run for this annotation

Mintlify / Mintlify Validation (allhandsai) - vale-spellcheck

sdk/api-reference/openhands.sdk.llm.mdx#L554

Did you really mean 'function_call'?

#### to_chat_dict()

Expand All @@ -550,10 +561,10 @@
* `cache_enabled` – Whether prompt caching is active.
* `vision_enabled` – Whether vision/image processing is enabled.
* `function_calling_enabled` – Whether native function calling is enabled.
* `force_string_serializer` – Force string serializer instead of list format.

Check warning on line 564 in sdk/api-reference/openhands.sdk.llm.mdx

View check run for this annotation

Mintlify / Mintlify Validation (allhandsai) - vale-spellcheck

sdk/api-reference/openhands.sdk.llm.mdx#L564

Did you really mean 'serializer'?
* `send_reasoning_content` – Whether to include reasoning_content in output.

Check warning on line 565 in sdk/api-reference/openhands.sdk.llm.mdx

View check run for this annotation

Mintlify / Mintlify Validation (allhandsai) - vale-spellcheck

sdk/api-reference/openhands.sdk.llm.mdx#L565

Did you really mean 'reasoning_content'?

Chooses the appropriate content serializer and then injects threading keys:

Check warning on line 567 in sdk/api-reference/openhands.sdk.llm.mdx

View check run for this annotation

Mintlify / Mintlify Validation (allhandsai) - vale-spellcheck

sdk/api-reference/openhands.sdk.llm.mdx#L567

Did you really mean 'serializer'?
- Assistant tool call turn: role == “assistant” and self.tool_calls
- Tool result turn: role == “tool” and self.tool_call_id (with name)

Expand All @@ -563,12 +574,12 @@

Produces a list of “input” items for the Responses API:
- system: returns [], system content is expected in ‘instructions’
- user: one ‘message’ item with content parts -> input_text / input_image

Check warning on line 577 in sdk/api-reference/openhands.sdk.llm.mdx

View check run for this annotation

Mintlify / Mintlify Validation (allhandsai) - vale-spellcheck

sdk/api-reference/openhands.sdk.llm.mdx#L577

Did you really mean 'input_text'?

Check warning on line 577 in sdk/api-reference/openhands.sdk.llm.mdx

View check run for this annotation

Mintlify / Mintlify Validation (allhandsai) - vale-spellcheck

sdk/api-reference/openhands.sdk.llm.mdx#L577

Did you really mean 'input_image'?
(when vision enabled)
- assistant: emits prior assistant content as input_text,

Check warning on line 579 in sdk/api-reference/openhands.sdk.llm.mdx

View check run for this annotation

Mintlify / Mintlify Validation (allhandsai) - vale-spellcheck

sdk/api-reference/openhands.sdk.llm.mdx#L579

Did you really mean 'input_text'?
and function_call items for tool_calls

Check warning on line 580 in sdk/api-reference/openhands.sdk.llm.mdx

View check run for this annotation

Mintlify / Mintlify Validation (allhandsai) - vale-spellcheck

sdk/api-reference/openhands.sdk.llm.mdx#L580

Did you really mean 'function_call'?

Check warning on line 580 in sdk/api-reference/openhands.sdk.llm.mdx

View check run for this annotation

Mintlify / Mintlify Validation (allhandsai) - vale-spellcheck

sdk/api-reference/openhands.sdk.llm.mdx#L580

Did you really mean 'tool_calls'?
- tool: emits function_call_output items (one per TextContent)

Check warning on line 581 in sdk/api-reference/openhands.sdk.llm.mdx

View check run for this annotation

Mintlify / Mintlify Validation (allhandsai) - vale-spellcheck

sdk/api-reference/openhands.sdk.llm.mdx#L581

Did you really mean 'function_call_output'?
with matching call_id

Check warning on line 582 in sdk/api-reference/openhands.sdk.llm.mdx

View check run for this annotation

Mintlify / Mintlify Validation (allhandsai) - vale-spellcheck

sdk/api-reference/openhands.sdk.llm.mdx#L582

Did you really mean 'call_id'?

#### to_responses_value()

Expand All @@ -583,7 +594,7 @@
Transport-agnostic tool call representation.

One canonical id is used for linking across actions/observations and
for Responses function_call_output call_id.

Check warning on line 597 in sdk/api-reference/openhands.sdk.llm.mdx

View check run for this annotation

Mintlify / Mintlify Validation (allhandsai) - vale-spellcheck

sdk/api-reference/openhands.sdk.llm.mdx#L597

Did you really mean 'function_call_output'?

Check warning on line 597 in sdk/api-reference/openhands.sdk.llm.mdx

View check run for this annotation

Mintlify / Mintlify Validation (allhandsai) - vale-spellcheck

sdk/api-reference/openhands.sdk.llm.mdx#L597

Did you really mean 'call_id'?


#### Properties
Expand All @@ -598,27 +609,27 @@

#### Methods

#### classmethod from_chat_tool_call()

Check warning on line 612 in sdk/api-reference/openhands.sdk.llm.mdx

View check run for this annotation

Mintlify / Mintlify Validation (allhandsai) - vale-spellcheck

sdk/api-reference/openhands.sdk.llm.mdx#L612

Did you really mean 'classmethod'?

Create a MessageToolCall from a Chat Completions tool call.

#### classmethod from_responses_function_call()

Check warning on line 616 in sdk/api-reference/openhands.sdk.llm.mdx

View check run for this annotation

Mintlify / Mintlify Validation (allhandsai) - vale-spellcheck

sdk/api-reference/openhands.sdk.llm.mdx#L616

Did you really mean 'classmethod'?

Create a MessageToolCall from a typed OpenAI Responses function_call item.

Check warning on line 618 in sdk/api-reference/openhands.sdk.llm.mdx

View check run for this annotation

Mintlify / Mintlify Validation (allhandsai) - vale-spellcheck

sdk/api-reference/openhands.sdk.llm.mdx#L618

Did you really mean 'function_call'?

Note: OpenAI Responses function_call.arguments is already a JSON string.

#### model_config = (configuration object)

Check warning on line 622 in sdk/api-reference/openhands.sdk.llm.mdx

View check run for this annotation

Mintlify / Mintlify Validation (allhandsai) - vale-spellcheck

sdk/api-reference/openhands.sdk.llm.mdx#L622

Did you really mean 'model_config'?

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

#### to_chat_dict()

Serialize to OpenAI Chat Completions tool_calls format.

Check warning on line 628 in sdk/api-reference/openhands.sdk.llm.mdx

View check run for this annotation

Mintlify / Mintlify Validation (allhandsai) - vale-spellcheck

sdk/api-reference/openhands.sdk.llm.mdx#L628

Did you really mean 'tool_calls'?

#### to_responses_dict()

Serialize to OpenAI Responses ‘function_call’ input item format.

Check warning on line 632 in sdk/api-reference/openhands.sdk.llm.mdx

View check run for this annotation

Mintlify / Mintlify Validation (allhandsai) - vale-spellcheck

sdk/api-reference/openhands.sdk.llm.mdx#L632

Did you really mean 'function_call'?

#### add_cost()

Expand Down Expand Up @@ -661,11 +672,11 @@

Merge ‘other’ metrics into this one.

#### model_config = (configuration object)

Check warning on line 675 in sdk/api-reference/openhands.sdk.llm.mdx

View check run for this annotation

Mintlify / Mintlify Validation (allhandsai) - vale-spellcheck

sdk/api-reference/openhands.sdk.llm.mdx#L675

Did you really mean 'model_config'?

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

#### classmethod validate_accumulated_cost()

Check warning on line 679 in sdk/api-reference/openhands.sdk.llm.mdx

View check run for this annotation

Mintlify / Mintlify Validation (allhandsai) - vale-spellcheck

sdk/api-reference/openhands.sdk.llm.mdx#L679

Did you really mean 'classmethod'?

### class MetricsSnapshot

Expand All @@ -685,7 +696,7 @@

#### Methods

#### model_config = (configuration object)

Check warning on line 699 in sdk/api-reference/openhands.sdk.llm.mdx

View check run for this annotation

Mintlify / Mintlify Validation (allhandsai) - vale-spellcheck

sdk/api-reference/openhands.sdk.llm.mdx#L699

Did you really mean 'model_config'?

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

Expand All @@ -710,7 +721,7 @@

Check if the access token is expired.

#### model_config = (configuration object)

Check warning on line 724 in sdk/api-reference/openhands.sdk.llm.mdx

View check run for this annotation

Mintlify / Mintlify Validation (allhandsai) - vale-spellcheck

sdk/api-reference/openhands.sdk.llm.mdx#L724

Did you really mean 'model_config'?

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

Expand Down Expand Up @@ -795,7 +806,7 @@

OpenAI Responses reasoning item (non-stream, subset we consume).

Do not log or render encrypted_content.

Check warning on line 809 in sdk/api-reference/openhands.sdk.llm.mdx

View check run for this annotation

Mintlify / Mintlify Validation (allhandsai) - vale-spellcheck

sdk/api-reference/openhands.sdk.llm.mdx#L809

Did you really mean 'encrypted_content'?


#### Properties
Expand All @@ -808,7 +819,7 @@

#### Methods

#### model_config = (configuration object)

Check warning on line 822 in sdk/api-reference/openhands.sdk.llm.mdx

View check run for this annotation

Mintlify / Mintlify Validation (allhandsai) - vale-spellcheck

sdk/api-reference/openhands.sdk.llm.mdx#L822

Did you really mean 'model_config'?

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

Expand All @@ -829,7 +840,7 @@

#### Methods

#### model_config = (configuration object)

Check warning on line 843 in sdk/api-reference/openhands.sdk.llm.mdx

View check run for this annotation

Mintlify / Mintlify Validation (allhandsai) - vale-spellcheck

sdk/api-reference/openhands.sdk.llm.mdx#L843

Did you really mean 'model_config'?

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

Expand All @@ -852,7 +863,7 @@
inheriting from LLM, allowing routers to work with multiple underlying
LLM models while presenting a unified LLM interface to consumers.
Key features:
- Works with multiple LLMs configured via llms_for_routing

Check warning on line 866 in sdk/api-reference/openhands.sdk.llm.mdx

View check run for this annotation

Mintlify / Mintlify Validation (allhandsai) - vale-spellcheck

sdk/api-reference/openhands.sdk.llm.mdx#L866

Did you really mean 'LLMs'?

Check warning on line 866 in sdk/api-reference/openhands.sdk.llm.mdx

View check run for this annotation

Mintlify / Mintlify Validation (allhandsai) - vale-spellcheck

sdk/api-reference/openhands.sdk.llm.mdx#L866

Did you really mean 'llms_for_routing'?
- Delegates all other operations/properties to the selected LLM
- Provides routing interface through select_llm() method

Expand All @@ -876,13 +887,13 @@
* `messages` – List of conversation messages
* `tools` – Optional list of tools available to the model
* `return_metrics` – Whether to return usage metrics
* `add_security_risk_prediction` – Add security_risk field to tool schemas

Check warning on line 890 in sdk/api-reference/openhands.sdk.llm.mdx

View check run for this annotation

Mintlify / Mintlify Validation (allhandsai) - vale-spellcheck

sdk/api-reference/openhands.sdk.llm.mdx#L890

Did you really mean 'security_risk'?
* `on_token` – Optional callback for streaming tokens
kwargs* – Additional arguments passed to the LLM API

#### NOTE
Summary field is always added to tool schemas for transparency and
explainability of agent actions.

Check warning on line 896 in sdk/api-reference/openhands.sdk.llm.mdx

View check run for this annotation

Mintlify / Mintlify Validation (allhandsai) - vale-spellcheck

sdk/api-reference/openhands.sdk.llm.mdx#L896

Did you really mean 'explainability'?

#### model_post_init()

Expand All @@ -894,25 +905,25 @@
* `self` – The BaseModel instance.
* `context` – The context.

#### abstractmethod select_llm()

Check warning on line 908 in sdk/api-reference/openhands.sdk.llm.mdx

View check run for this annotation

Mintlify / Mintlify Validation (allhandsai) - vale-spellcheck

sdk/api-reference/openhands.sdk.llm.mdx#L908

Did you really mean 'abstractmethod'?

Select which LLM to use based on messages and events.

This method implements the core routing logic for the RouterLLM.
Subclasses should analyze the provided messages to determine which
LLM from llms_for_routing is most appropriate for handling the request.

Check warning on line 914 in sdk/api-reference/openhands.sdk.llm.mdx

View check run for this annotation

Mintlify / Mintlify Validation (allhandsai) - vale-spellcheck

sdk/api-reference/openhands.sdk.llm.mdx#L914

Did you really mean 'llms_for_routing'?

* Parameters:
`messages` – List of messages in the conversation that can be used
to inform the routing decision.
* Returns:
The key/name of the LLM to use from llms_for_routing dictionary.

Check warning on line 920 in sdk/api-reference/openhands.sdk.llm.mdx

View check run for this annotation

Mintlify / Mintlify Validation (allhandsai) - vale-spellcheck

sdk/api-reference/openhands.sdk.llm.mdx#L920

Did you really mean 'llms_for_routing'?

#### classmethod set_placeholder_model()

Check warning on line 922 in sdk/api-reference/openhands.sdk.llm.mdx

View check run for this annotation

Mintlify / Mintlify Validation (allhandsai) - vale-spellcheck

sdk/api-reference/openhands.sdk.llm.mdx#L922

Did you really mean 'classmethod'?

Guarantee model exists before LLM base validation runs.

#### classmethod validate_llms_not_empty()

Check warning on line 926 in sdk/api-reference/openhands.sdk.llm.mdx

View check run for this annotation

Mintlify / Mintlify Validation (allhandsai) - vale-spellcheck

sdk/api-reference/openhands.sdk.llm.mdx#L926

Did you really mean 'classmethod'?

### class TextContent

Expand Down Expand Up @@ -951,6 +962,6 @@

#### Methods

#### model_config = (configuration object)

Check warning on line 965 in sdk/api-reference/openhands.sdk.llm.mdx

View check run for this annotation

Mintlify / Mintlify Validation (allhandsai) - vale-spellcheck

sdk/api-reference/openhands.sdk.llm.mdx#L965

Did you really mean 'model_config'?

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
15 changes: 15 additions & 0 deletions sdk/api-reference/openhands.sdk.utils.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,21 @@

Utility functions for the OpenHands SDK.


## Import shortcuts

`page_iterator` is publicly exported from `openhands.sdk.utils` and from the top-level `openhands.sdk` package.

```python
from openhands.sdk.utils import page_iterator
# or
from openhands.sdk import page_iterator
```

### page_iterator()

Iterate over items from paginated search results.

### deprecated()

Return a decorator that deprecates a callable with explicit metadata.
Expand Down Expand Up @@ -60,15 +75,15 @@

Return a copy of env with sanitized values.

PyInstaller-based binaries rewrite `LD_LIBRARY_PATH` so their vendored

Check warning on line 78 in sdk/api-reference/openhands.sdk.utils.mdx

View check run for this annotation

Mintlify / Mintlify Validation (allhandsai) - vale-spellcheck

sdk/api-reference/openhands.sdk.utils.mdx#L78

Did you really mean 'vendored'?
libraries win. This function restores the original value so that subprocess

Check warning on line 79 in sdk/api-reference/openhands.sdk.utils.mdx

View check run for this annotation

Mintlify / Mintlify Validation (allhandsai) - vale-spellcheck

sdk/api-reference/openhands.sdk.utils.mdx#L79

Did you really mean 'subprocess'?
will not use them.

### warn_deprecated()

Emit a deprecation warning for dynamic access to a legacy feature.

Prefer this helper when a decorator is not practical—e.g. attribute accessors,

Check warning on line 86 in sdk/api-reference/openhands.sdk.utils.mdx

View check run for this annotation

Mintlify / Mintlify Validation (allhandsai) - vale-spellcheck

sdk/api-reference/openhands.sdk.utils.mdx#L86

Did you really mean 'accessors'?
data migrations, or other runtime paths that must conditionally warn. Provide
explicit version metadata so the SDK reports consistent messages and upgrades
to `deprecation.UnsupportedWarning` after the removal threshold.
11 changes: 11 additions & 0 deletions sdk/api-reference/openhands.sdk.workspace.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,24 @@
---


## Import shortcuts

`AsyncRemoteWorkspace` is publicly exported from `openhands.sdk.workspace.remote`, `openhands.sdk.workspace`, and the top-level `openhands.sdk` package.

```python
from openhands.sdk.workspace import AsyncRemoteWorkspace
# or
from openhands.sdk import AsyncRemoteWorkspace
```


### class BaseWorkspace

Bases: `DiscriminatedUnionMixin`, `ABC`

Abstract base class for workspace implementations.

Workspaces provide a sandboxed environment where agents can execute commands,

Check warning on line 24 in sdk/api-reference/openhands.sdk.workspace.mdx

View check run for this annotation

Mintlify / Mintlify Validation (allhandsai) - vale-spellcheck

sdk/api-reference/openhands.sdk.workspace.mdx#L24

Did you really mean 'sandboxed'?
read/write files, and perform other operations. All workspace implementations
support the context manager protocol for safe resource management.

Expand All @@ -29,7 +40,7 @@

#### Methods

#### abstractmethod execute_command()

Check warning on line 43 in sdk/api-reference/openhands.sdk.workspace.mdx

View check run for this annotation

Mintlify / Mintlify Validation (allhandsai) - vale-spellcheck

sdk/api-reference/openhands.sdk.workspace.mdx#L43

Did you really mean 'abstractmethod'?

Execute a bash command on the system.

Expand All @@ -38,14 +49,14 @@
* `cwd` – Working directory for the command (optional)
* `timeout` – Timeout in seconds (defaults to 30.0)
* Returns:
Result containing stdout, stderr, exit_code, and other

Check warning on line 52 in sdk/api-reference/openhands.sdk.workspace.mdx

View check run for this annotation

Mintlify / Mintlify Validation (allhandsai) - vale-spellcheck

sdk/api-reference/openhands.sdk.workspace.mdx#L52

Did you really mean 'exit_code'?
: metadata
* Return type:
[CommandResult](#class-commandresult)
* Raises:
`Exception` – If command execution fails

#### abstractmethod file_download()

Check warning on line 59 in sdk/api-reference/openhands.sdk.workspace.mdx

View check run for this annotation

Mintlify / Mintlify Validation (allhandsai) - vale-spellcheck

sdk/api-reference/openhands.sdk.workspace.mdx#L59

Did you really mean 'abstractmethod'?

Download a file from the system.

Expand All @@ -59,7 +70,7 @@
* Raises:
`Exception` – If file download fails

#### abstractmethod file_upload()

Check warning on line 73 in sdk/api-reference/openhands.sdk.workspace.mdx

View check run for this annotation

Mintlify / Mintlify Validation (allhandsai) - vale-spellcheck

sdk/api-reference/openhands.sdk.workspace.mdx#L73

Did you really mean 'abstractmethod'?

Upload a file to the system.

Expand All @@ -73,7 +84,7 @@
* Raises:
`Exception` – If file upload fails

#### abstractmethod git_changes()

Check warning on line 87 in sdk/api-reference/openhands.sdk.workspace.mdx

View check run for this annotation

Mintlify / Mintlify Validation (allhandsai) - vale-spellcheck

sdk/api-reference/openhands.sdk.workspace.mdx#L87

Did you really mean 'abstractmethod'?

Get the git changes for the repository at the path given.

Expand All @@ -86,7 +97,7 @@
* Raises:
`Exception` – If path is not a git repository or getting changes failed

#### abstractmethod git_diff()

Check warning on line 100 in sdk/api-reference/openhands.sdk.workspace.mdx

View check run for this annotation

Mintlify / Mintlify Validation (allhandsai) - vale-spellcheck

sdk/api-reference/openhands.sdk.workspace.mdx#L100

Did you really mean 'abstractmethod'?

Get the git diff for the file at the path given.

Expand All @@ -99,7 +110,7 @@
* Raises:
`Exception` – If path is not a git repository or getting diff failed

#### model_config = (configuration object)

Check warning on line 113 in sdk/api-reference/openhands.sdk.workspace.mdx

View check run for this annotation

Mintlify / Mintlify Validation (allhandsai) - vale-spellcheck

sdk/api-reference/openhands.sdk.workspace.mdx#L113

Did you really mean 'model_config'?

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

Expand Down Expand Up @@ -140,7 +151,7 @@

#### Methods

#### model_config = (configuration object)

Check warning on line 154 in sdk/api-reference/openhands.sdk.workspace.mdx

View check run for this annotation

Mintlify / Mintlify Validation (allhandsai) - vale-spellcheck

sdk/api-reference/openhands.sdk.workspace.mdx#L154

Did you really mean 'model_config'?

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

Expand All @@ -161,7 +172,7 @@

#### Methods

#### model_config = (configuration object)

Check warning on line 175 in sdk/api-reference/openhands.sdk.workspace.mdx

View check run for this annotation

Mintlify / Mintlify Validation (allhandsai) - vale-spellcheck

sdk/api-reference/openhands.sdk.workspace.mdx#L175

Did you really mean 'model_config'?

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

Expand Down Expand Up @@ -207,8 +218,8 @@
* `cwd` – Working directory (optional)
* `timeout` – Timeout in seconds
* Returns:
Result with stdout, stderr, exit_code, command, and

Check warning on line 221 in sdk/api-reference/openhands.sdk.workspace.mdx

View check run for this annotation

Mintlify / Mintlify Validation (allhandsai) - vale-spellcheck

sdk/api-reference/openhands.sdk.workspace.mdx#L221

Did you really mean 'exit_code'?
: timeout_occurred

Check warning on line 222 in sdk/api-reference/openhands.sdk.workspace.mdx

View check run for this annotation

Mintlify / Mintlify Validation (allhandsai) - vale-spellcheck

sdk/api-reference/openhands.sdk.workspace.mdx#L222

Did you really mean 'timeout_occurred'?
* Return type:
[CommandResult](#class-commandresult)

Expand Down Expand Up @@ -268,7 +279,7 @@
* Raises:
`Exception` – If path is not a git repository or getting diff failed

#### model_config = (configuration object)

Check warning on line 282 in sdk/api-reference/openhands.sdk.workspace.mdx

View check run for this annotation

Mintlify / Mintlify Validation (allhandsai) - vale-spellcheck

sdk/api-reference/openhands.sdk.workspace.mdx#L282

Did you really mean 'model_config'?

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

Expand All @@ -292,7 +303,7 @@

Remote workspace implementation that connects to an OpenHands agent server.

RemoteWorkspace provides access to a sandboxed environment running on a remote

Check warning on line 306 in sdk/api-reference/openhands.sdk.workspace.mdx

View check run for this annotation

Mintlify / Mintlify Validation (allhandsai) - vale-spellcheck

sdk/api-reference/openhands.sdk.workspace.mdx#L306

Did you really mean 'sandboxed'?
OpenHands agent server. This is the recommended approach for production deployments
as it provides better isolation and security.

Expand Down Expand Up @@ -331,7 +342,7 @@
* `cwd` – Working directory (optional)
* `timeout` – Timeout in seconds
* Returns:
Result with stdout, stderr, exit_code, and other metadata

Check warning on line 345 in sdk/api-reference/openhands.sdk.workspace.mdx

View check run for this annotation

Mintlify / Mintlify Validation (allhandsai) - vale-spellcheck

sdk/api-reference/openhands.sdk.workspace.mdx#L345

Did you really mean 'exit_code'?
* Return type:
[CommandResult](#class-commandresult)

Expand Down Expand Up @@ -389,20 +400,20 @@
* Raises:
`Exception` – If path is not a git repository or getting diff failed

#### model_config = (configuration object)

Check warning on line 403 in sdk/api-reference/openhands.sdk.workspace.mdx

View check run for this annotation

Mintlify / Mintlify Validation (allhandsai) - vale-spellcheck

sdk/api-reference/openhands.sdk.workspace.mdx#L403

Did you really mean 'model_config'?

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

#### model_post_init()

Override this method to perform additional initialization after __init__ and model_construct.

Check warning on line 409 in sdk/api-reference/openhands.sdk.workspace.mdx

View check run for this annotation

Mintlify / Mintlify Validation (allhandsai) - vale-spellcheck

sdk/api-reference/openhands.sdk.workspace.mdx#L409

Did you really mean 'model_construct'?
This is useful if you want to do some validation that requires the entire model to be initialized.

#### reset_client()

Reset the HTTP client to force re-initialization.

This is useful when connection parameters (host, api_key) have changed

Check warning on line 416 in sdk/api-reference/openhands.sdk.workspace.mdx

View check run for this annotation

Mintlify / Mintlify Validation (allhandsai) - vale-spellcheck

sdk/api-reference/openhands.sdk.workspace.mdx#L416

Did you really mean 'api_key'?
and the client needs to be recreated with new values.

### class Workspace
Expand Down
Loading