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::parse_and_validate_tool_args;pub use tools::parse_tool_args;pub use tools::respond_to_tool_call;pub use tools::respond_to_tool_call_json;pub use tools::sync_handler;pub use tools::tool_result_message;pub use tools::tool_result_message_json;pub use tools::BoxFuture;pub use tools::ParseResult;pub use tools::ResponseExt;pub use tools::RetryOptions;pub use tools::ToolArgsError;pub use tools::ToolCallAccumulator;pub use tools::ToolExecutionResult;pub use tools::ToolHandler;pub use tools::ToolRegistry;pub use tools::UnknownToolError;pub use tools::ValidateArgs;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::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.
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.
- 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.
- Binding
Builder - Fluent builder for constructing bindings.
- Client
- Async client for the ModelRelay API.
- Client
Builder - Builder for constructing a
Clientwith explicit configuration. - Code
Exec Config - Code execution configuration.
- Condition
V1 - Edge condition for workflow.v1.
- 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.
- EdgeV1
- An edge connecting two nodes in the workflow.v1 DAG.
- Execution
V1 - Execution configuration for a workflow.v1.
- Field
Error - Field-level validation error returned by the API.
- 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
AnyInput V1 - Join
Collect Input V1 - List
Sessions Options - Options for listing sessions.
- LlmResponses
Binding V1 - LlmResponses
Node Options V1 - LlmResponses
Tool Limits V1 - 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
Input V1 - MapFanout
Item Binding V1 - MapFanout
Items V1 - MapFanout
SubNode V1 - Metrics
Callbacks - User-provided callbacks for emitting metrics without taking on a tracing dependency.
- Model
- Model identifier (string wrapper).
- Node
Result V0 - Result of a completed node.
- NodeV1
- A node in the workflow.v1 DAG.
- Output
Format - Output format configuration (structured outputs).
- Output
RefV1 - Reference to a workflow.v1 output.
- Payload
Info V0 - Metadata about a payload (node output or run outputs).
- 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 Response - Runs
GetResponse - 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.
- 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
Execution V1 - Transform
Json Input V1 - Transform
Json Value V1 - 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.
- WebTool
Config - Web tool configuration.
- Workflow
Builder V1 - Workflow
Spec V1 - Workflow specification (v1).
- 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 V1 - XSearch
Config - X/Twitter search configuration.
Enums§
- ApiKey
- Condition
OpV1 - Condition operator for workflow.v1 edges.
- Condition
Source V1 - Condition source for workflow.v1 edges.
- Content
Part - Content part within a message (currently only
text). - 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. - LlmResponses
Binding Encoding V1 - Local
Tool Error - Error type for local tool pack operations.
- Node
Type V1 - Node type within a workflow.v1.
- Output
Format Kind - Supported output format types.
- Output
Item - Output item returned by
/responses. - 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
Execution Mode V1 - Tool
Type - Tool type identifiers.
- Transport
Error Kind - Broad transport error kinds for classification.
- WebTool
Intent - Web tool intent (user-facing).
- Workflow
Kind - Workflow specification version.
- Workflows
Compile Result V1
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_
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).
- REQUEST_
ID_ HEADER - HTTP header name for request ID tracing.
- RUN_
EVENT_ V0_ SCHEMA_ JSON - JSON Schema for run_event.v2 events.
- WORKFLOW_
V1_ SCHEMA_ JSON - JSON Schema for workflow.v1 specifications.
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§
- bind_
to_ placeholder - Create a binding that injects a value into a {{placeholder}} in the prompt. Uses json_string encoding by default.
- bind_
to_ placeholder_ with_ pointer - Create a binding with a source pointer that injects into a placeholder.
- bind_
to_ pointer - Create a binding that injects a value at a specific JSON pointer in the request. Uses json_string encoding by default.
- bind_
to_ pointer_ with_ source - Create a binding with both source and destination pointers.
- 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. - 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.
- when_
output_ equals - Create a condition that matches when a node’s output equals a specific value.
- when_
output_ exists - Create a condition that matches when a path exists in the node’s output.
- when_
output_ matches - Create a condition that matches when a node’s output matches a regex pattern.
- when_
status_ equals - Create a condition that matches when a node’s status equals a specific value.
- when_
status_ exists - Create a condition that matches when a path exists in the node’s status.
- when_
status_ matches - Create a condition that matches when a node’s status matches a regex pattern.
- 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_
v1
Type Aliases§
- Local
Bash Option - Configuration options for the local bash tool pack.
- LocalFS
Option - Configuration options for the local filesystem tool pack.