Expand description
Minimal Rust SDK for the ModelRelay API.
Re-exports§
pub use tools::assistant_message_with_tool_calls;pub use tools::create_retry_messages;pub use tools::execute_with_retry;pub use tools::format_tool_error_for_model;pub use tools::get_retryable_errors;pub use tools::has_retryable_errors;pub use tools::is_user_ask_tool_call;pub use tools::parse_and_validate_tool_args;pub use tools::parse_tool_args;pub use tools::parse_user_ask_args;pub use tools::respond_to_tool_call;pub use tools::respond_to_tool_call_json;pub use tools::serialize_user_ask_result;pub use tools::sync_handler;pub use tools::tool_result_message;pub use tools::tool_result_message_json;pub use tools::user_ask_result_choice;pub use tools::user_ask_result_freeform;pub use tools::user_ask_tool;pub use tools::BoxFuture;pub use tools::ParseResult;pub use tools::ResponseExt;pub use tools::RetryOptions;pub use tools::ToolArgsError;pub use tools::ToolBuilder;pub use tools::ToolCallAccumulator;pub use tools::ToolExecutionResult;pub use tools::ToolHandler;pub use tools::ToolRegistry;pub use tools::TypedTool;pub use tools::TypedToolCall;pub use tools::UnknownToolError;pub use tools::UserAskArgs;pub use tools::UserAskOption;pub use tools::UserAskResponse;pub use tools::ValidateArgs;pub use tools::USER_ASK_TOOL_NAME;pub use tools::function_tool_from_type;pub use tools::ToolSchema;pub use types::Citation;pub use types::MessageRole;pub use generated::ImageData;pub use generated::ImagePinResponse;pub use generated::ImageRequest;pub use generated::ImageResponse;pub use generated::ImageResponseFormat;pub use generated::ImageUsage;pub use generated::RunsPendingToolCallV0;pub use generated::RunsPendingToolsResponse;pub use generated::SessionCreateRequest;pub use generated::SessionListResponse;pub use generated::SessionMessageCreateRequest;pub use generated::SessionMessageResponse;pub use generated::SessionResponse;pub use generated::SessionWithMessagesResponse;pub use generated::StateHandleCreateRequest;pub use generated::StateHandleListResponse;pub use generated::StateHandleResponse;pub use generated::ToolCallId;pub use generated::ToolName;pub use identifiers::TierCode;pub use workflow::ModelId;pub use workflow::NodeErrorV0;pub use workflow::NodeId;pub use workflow::NodeStatusV0;pub use workflow::PlanHash;pub use workflow::ProviderId;pub use workflow::RequestId;pub use workflow::RunCostLineItemV0;pub use workflow::RunCostSummaryV0;pub use workflow::RunId;pub use workflow::RunStatusV0;pub use workflow::Sha256Hash;pub use token_providers::CustomerTokenResponse;
Modules§
- generated
- Generated types from OpenAPI spec.
Run
just generate-sdk-typesto regenerate from api/openapi/api.yaml. Auto-generated types from OpenAPI spec. - testing
- tools
- Tool helpers for ergonomic tool use with the ModelRelay API.
- wrapper_
v1
Macros§
- tool_
handler - Helper macro to create a tool handler from an async closure.
Structs§
- APIError
- Structured error envelope returned by the API.
- APIKey
- Representation of an API key record.
- Agent
Options - Options for
Client::agent. - Agent
Result - Result of running an agent.
- Agent
Usage - Usage tracking across an agent run.
- Artifact
Key - Artifact key type for node outputs and run outputs.
- Attempt
Record - Record of a single structured output attempt.
- Auth
Client - Async client for customer token operations.
- Bash
Policy - Semantic bash policy with safety rails.
- Bash
Result - Result of a bash command execution.
- Bash
Tokens - Tokenized representation of a bash command string.
- Batch
Error - Error details for an individual batch item.
- Batch
Options - Batch execution options for
/responses/batch. - Batch
Request Item - Request item for batch responses.
- Batch
Response - Response payload for batch responses.
- Batch
Result - Result for a single batch item.
- Batch
Usage - Aggregate usage for batch responses.
- Chain
Options - Options for chain() helper.
- Chat
Options - Options for
Client::chatandClient::ask. - Client
- Async client for the ModelRelay API.
- Client
Builder - Builder for constructing a
Clientwith explicit configuration. - Code
Exec Config - Code execution configuration.
- Config
- Configuration for the async ModelRelay client.
- Customer
Responses Client - Responses client scoped to a specific customer id.
- Customer
Scoped Client - Customer-scoped client that automatically applies the customer id header.
- Customer
Token - Short-lived bearer token usable from browser/mobile clients.
- Customer
Token Provider - Token provider that mints customer bearer tokens using a secret key.
- Customer
Token Provider Config - Configuration for
CustomerTokenProvider. - Customer
Token Request - Request payload for POST /auth/customer-token.
- Date
Time - ISO 8601 combined date and time with time zone.
- Default
Retry Handler - Default retry handler that appends a simple error correction message.
- Field
Error - Field-level validation error returned by the API.
- File
Content - File content within a content part.
- Function
Call - Function call details in a tool call.
- Function
Call Delta - Incremental function call data.
- Function
Tool - Function tool definition.
- GetOr
Create Customer Token Request - Request to get or create a customer and mint a token.
- Header
Entry - Header
List - Structured header/metadata list with validation.
- Http
Request Metrics - HTTP request latency and outcome.
- Images
Client - Client for image generation operations.
- JSON
Schema Format - JSON schema payload for structured outputs.
- Join
Collect Options - LLMNode
Builder - List
Sessions Options - Options for listing sessions.
- List
State Handles Options - Options for listing state handles.
- Local
Bash Tool Pack - LocalBashToolPack provides safe-by-default bash command execution.
- LocalFS
Tool Pack - LocalFSToolPack provides safe-by-default implementations of tools.v0 filesystem tools:
- MapFanout
Options - Metrics
Callbacks - User-provided callbacks for emitting metrics without taking on a tracing dependency.
- Mime
Type - IANA media type string (e.g., “image/png”, “application/pdf”).
- Model
- Model identifier (string wrapper).
- Node
Result V0 - Result of a completed node.
- Output
Format - Output format configuration (structured outputs).
- Parallel
Options - Options for parallel() helper.
- Payload
Info V0 - Metadata about a payload (node output or run outputs).
- Plugin
- Plugin
Agent - Plugin
Agent Name - Plugin
Command - Plugin
Command Name - Plugin
Converter - Plugin
Converter Options - Plugin
GitHub Ref - Plugin
Id - Plugin
Loader - Plugin
Loader Options - Plugin
Manifest - Plugin
Orchestration Error - Plugin
RunConfig - Plugin
RunError - Plugin
RunResult - Plugin
Url - Plugins
Client - Plugins
Client Options - Poll
Until Options - Configuration for polling with backoff.
- Request
Context - Common request metadata shared by all telemetry events.
- Response
- Aggregated response returned by
POST /responses. - Response
Builder - Builder for
POST /responses(async). - Response
Options - Optional headers for
POST /responsescalls. - Response
Stream Adapter - Adapter that yields only text deltas from a stream handle.
- Responses
Client - Async client for
POST /responses. - Retry
Config - Retry/backoff configuration (defaults use 3 attempts + jittered exponential backoff).
- Retry
Metadata - Retry metadata surfaced on transport/API errors when retries were attempted.
- RunEvent
Envelope - Common envelope fields for all run events.
- RunEvent
Stream Handle streaming - RunEvent
V0 - A run event with envelope metadata and payload.
- Runs
Client - Runs
Create Options - Runs
Create Response - Runs
Fanout Subnode Override - Runs
GetResponse - Runs
Model Overrides - Runs
Tool Call V0 - Runs
Tool Result Item V0 - Runs
Tool Results Request - Runs
Tool Results Response - Secret
Key - Sessions
Client - Client for session operations.
- SqlClient
- Client for SQL validation operations.
- SqlColumn
Info - SqlExecute
Result - SqlTable
Description - SqlTable
Info - SqlTool
Loop Builder - SqlTool
Loop Handlers - SqlTool
Loop Options - SqlTool
Loop Result - State
Handles Client - Client for state handle operations.
- Stream
Event - Single SSE event emitted by the streaming proxy.
- Stream
First Token Metrics - Time from request start to the first streaming token/event.
- Stream
Handle streaming - Streaming handle over NDJSON response events.
- Stream
Timeout Error - Typed error for streaming timeouts.
- Structured
Decode Error - Error returned when structured output fails on first attempt (before retries).
- Structured
Exhausted Error - Error returned when all retry attempts are exhausted.
- StructuredJSON
Event - Structured JSON event (parsed from NDJSON envelope).
- StructuredJSON
Stream streaming - Helper over NDJSON streaming events to yield structured JSON payloads.
- Structured
Options - Options for structured output requests.
- Structured
Result - Result of a successful structured output request.
- Tier
- Tier
Checkout Request - Request to create a tier checkout session (checkout-first flow). Stripe collects the customer’s email during checkout.
- Tier
Checkout Session - Tier checkout session response.
- Tier
Model - A model with cost information in a tier. Customer prices are derived from model costs: price = cost * (1 + platformFeePercent/100).
- Tiers
Client - Client for tier querying operations.
- Token
Usage Metrics - Token usage surfaced once a request/stream finishes.
- Tool
- A tool available for the model to call.
- Tool
Call - A tool call made by the model.
- Tool
Call Delta - Incremental update to a tool call during streaming.
- Tool
Choice - Controls how the model responds to tool calls.
- Tool
Result Item - A tool result item for use with continuation helpers.
- Transport
Error - Transport-level error (timeouts, DNS/TLS/connectivity).
- Usage
- Token usage metadata.
- Usage
Summary - Utc
- The UTC time zone. This is the most efficient time zone when you don’t need the local time. It is also used as an offset (which is also a dummy type).
- Uuid
- A Universally Unique Identifier (UUID).
- Validation
Error - Structured validation/build error returned by the SDK.
- Validation
Issue - A single field-level validation issue.
- Workflow
Intent Builder - Workflow
Intent Condition - Condition used by join.any/join.collect predicates.
- Workflow
Intent Input Decl - Workflow input declaration.
- Workflow
Intent Node - A node in the workflow DAG.
- Workflow
Intent Output Ref - Reference to a workflow output.
- Workflow
Intent Spec - Workflow specification.
- Workflow
Intent Tool Execution - Tool execution configuration for LLM nodes.
- Workflow
Intent Transform Value - Transform value reference for transform.json nodes.
- Workflow
Validation Error - Typed workflow validation error surfaced by the SDK.
- Workflow
Validation Issue - Workflow semantic validation error returned by the API compiler (
/workflows/compile). - Workflows
Client - Workflows
Compile Response - XSearch
Config - X/Twitter search configuration.
Enums§
- ApiKey
- Batch
Status - Status for a batch item.
- Content
Part - Content part within a message.
- Envelope
Version - Envelope version for run events. Schema specifies const “v2”.
- Error
- Unified error type surfaced by the SDK.
- Input
Item - Input item sent to
/responses. - Local
Tool Error - Error type for local tool pack operations.
- Node
Type V1 - Node type within a workflow.v1.
- Orchestration
Mode - Output
Format Kind - Supported output format types.
- Output
Item - Output item returned by
/responses. - Plugin
Error - Plugin
Orchestration Error Code - Plugin
Tool Name - Poll
Result - Outcome of a polling attempt.
- Price
Interval - Billing interval for a tier.
- RunEvent
Payload - Event-specific payload data.
- RunEvent
Type V0 - Run event type discriminator.
- Stop
Reason - Stop reason returned by the backend and surfaced by
/responses. - Stream
Event Kind - High-level streaming event kinds emitted by the API.
- Stream
Timeout Kind - Which streaming timeout triggered.
- Structured
Error - Unified error type for structured output operations.
- Structured
Error Kind - Specific kind of structured output error.
- Structured
Record Kind - Kind of structured record.
- Subscription
Status Kind - Subscription status for billing integrations.
- Tool
Choice Type - Tool choice type.
- Tool
Type - Tool type identifiers.
- Transport
Error Kind - Broad transport error kinds for classification.
- Workflow
Intent Kind - Workflow specification kind.
- Workflow
Intent Node Type - Node type within a workflow.
- Workflow
Intent Tool Execution Mode - Tool execution mode for LLM nodes.
- Workflow
Intent Tool Ref - Tool reference for workflow.
- Workflows
Compile Result
Constants§
- CUSTOMER_
ID_ HEADER - HTTP header name for customer-attributed requests.
- DEFAULT_
BASE_ URL - Default API base URL.
- DEFAULT_
CONNECT_ TIMEOUT - Default connection timeout (5 seconds).
- DEFAULT_
MAX_ TURNS - Default maximum turns for agent loops.
- DEFAULT_
REQUEST_ TIMEOUT - Default request timeout (60 seconds).
- LLM_
TEXT_ OUTPUT - JSON pointer to extract text content from an LLM response output. Points to: output[0].content[0].text
- LLM_
USER_ MESSAGE_ TEXT - JSON pointer to inject text into the user message of an LLM request. Points to: input[1].content[0].text (index 1 assumes a system message at index 0). The pointer is relative to the request object (not the full node input).
- MAX_
STATE_ HANDLE_ TTL_ SECONDS - Maximum allowed TTL for a state handle (1 year in seconds).
- NO_
TURN_ LIMIT - Use this for max_turns to disable the turn limit. Use with caution as this can lead to infinite loops and runaway API costs.
- REQUEST_
ID_ HEADER - HTTP header name for request ID tracing.
- RUN_
EVENT_ V0_ SCHEMA_ JSON - JSON Schema for run_event.v2 events.
Traits§
- Message
Role Ext - Extension trait for MessageRole providing convenience methods.
- Retry
Handler - Handler for customizing retry behavior on validation failures.
- Token
Provider - Trait for token providers that supply bearer tokens for API requests.
Functions§
- chain
- Creates a sequential workflow where each step depends on the previous one. Edges are automatically wired based on order.
- get_
all_ tool_ calls_ from_ response - Extracts all tool calls from a response.
- llm
- Creates a standalone LLM node for use with chain() and parallel().
- new_
local_ bash_ tools - Creates a ToolRegistry with the LocalBashToolPack registered.
- new_
local_ fs_ tools - Creates a ToolRegistry with the LocalFSToolPack registered.
- output_
format_ from_ type - Generates an
OutputFormatwith automatic JSON schema from a type. - parallel
- Creates a parallel workflow where all steps run concurrently, then join. Edges are automatically wired to a join.all node.
- poll_
until - Poll until the closure returns a value or the deadline is exceeded.
- run_
node_ ref - Creates a reference string for a node within a run.
- tokenize_
bash - Tokenize a bash command string with lightweight detection and normalization.
- with_
bash_ allow_ env_ vars - Only passes the specified environment variables to the command.
- with_
bash_ hard_ max_ output_ bytes - Sets the hard cap for output bytes. This is the absolute maximum regardless of requested limits.
- with_
bash_ inherit_ env - Inherits all environment variables from the parent process.
- with_
bash_ max_ output_ bytes - Sets the soft limit for output bytes. Output beyond this limit will be truncated.
- with_
bash_ policy - Sets the bash policy for command execution.
- with_
bash_ timeout - Sets the timeout for command execution.
- with_
local_ fs_ hard_ max_ list_ entries - WithLocalFSHardMaxListEntries changes the hard cap for fs.list_files max_entries.
- with_
local_ fs_ hard_ max_ read_ bytes - WithLocalFSHardMaxReadBytes changes the hard cap for fs.read_file max_bytes.
- with_
local_ fs_ hard_ max_ search_ matches - WithLocalFSHardMaxSearchMatches changes the hard cap for fs.search max_matches.
- with_
local_ fs_ ignore_ dirs - WithLocalFSIgnoreDirs configures directory names to skip during fs.list_files and fs.search. Names are matched by path segment (e.g. “.git” skips any “.git” directory anywhere under root).
- with_
local_ fs_ max_ list_ entries - WithLocalFSMaxListEntries changes the default max_entries when the tool call does not specify max_entries.
- with_
local_ fs_ max_ read_ bytes - WithLocalFSMaxReadBytes changes the default max_bytes when the tool call does not specify max_bytes.
- with_
local_ fs_ max_ search_ bytes - WithLocalFSMaxSearchBytes sets a per-file byte limit for the fs.search implementation.
- with_
local_ fs_ max_ search_ matches - WithLocalFSMaxSearchMatches changes the default max_matches when the tool call does not specify max_matches.
- with_
local_ fs_ search_ timeout - WithLocalFSSearchTimeout configures the timeout for fs.search.
- workflow
- Alias for workflow_intent() with a cleaner name.
- workflow_
intent
Type Aliases§
- Intent
Kind - Intent
Spec - Local
Bash Option - Configuration options for the local bash tool pack.
- LocalFS
Option - Configuration options for the local filesystem tool pack.
- SqlRow