Crate modelrelay

Crate modelrelay 

Source
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-types to 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.
ArtifactKey
Artifact key type for node outputs and run outputs.
AttemptRecord
Record of a single structured output attempt.
AuthClient
Async client for customer token operations.
BashPolicy
Semantic bash policy with safety rails.
BashResult
Result of a bash command execution.
BashTokens
Tokenized representation of a bash command string.
BindingBuilder
Fluent builder for constructing bindings.
Client
Async client for the ModelRelay API.
ClientBuilder
Builder for constructing a Client with explicit configuration.
CodeExecConfig
Code execution configuration.
ConditionV1
Edge condition for workflow.v1.
Config
Configuration for the async ModelRelay client.
CustomerResponsesClient
Responses client scoped to a specific customer id.
CustomerScopedClient
Customer-scoped client that automatically applies the customer id header.
CustomerToken
Short-lived bearer token usable from browser/mobile clients.
CustomerTokenProvider
Token provider that mints customer bearer tokens using a secret key.
CustomerTokenProviderConfig
Configuration for CustomerTokenProvider.
CustomerTokenRequest
Request payload for POST /auth/customer-token.
DateTime
ISO 8601 combined date and time with time zone.
DefaultRetryHandler
Default retry handler that appends a simple error correction message.
EdgeV1
An edge connecting two nodes in the workflow.v1 DAG.
ExecutionV1
Execution configuration for a workflow.v1.
FieldError
Field-level validation error returned by the API.
FunctionCall
Function call details in a tool call.
FunctionCallDelta
Incremental function call data.
FunctionTool
Function tool definition.
GetOrCreateCustomerTokenRequest
Request to get or create a customer and mint a token.
HeaderEntry
HeaderList
Structured header/metadata list with validation.
HttpRequestMetrics
HTTP request latency and outcome.
ImagesClient
Client for image generation operations.
JSONSchemaFormat
JSON schema payload for structured outputs.
JoinAnyInputV1
JoinCollectInputV1
ListSessionsOptions
Options for listing sessions.
LlmResponsesBindingV1
LlmResponsesNodeOptionsV1
LlmResponsesToolLimitsV1
LocalBashToolPack
LocalBashToolPack provides safe-by-default bash command execution.
LocalFSToolPack
LocalFSToolPack provides safe-by-default implementations of tools.v0 filesystem tools:
MapFanoutInputV1
MapFanoutItemBindingV1
MapFanoutItemsV1
MapFanoutSubNodeV1
MetricsCallbacks
User-provided callbacks for emitting metrics without taking on a tracing dependency.
Model
Model identifier (string wrapper).
NodeResultV0
Result of a completed node.
NodeV1
A node in the workflow.v1 DAG.
OutputFormat
Output format configuration (structured outputs).
OutputRefV1
Reference to a workflow.v1 output.
PayloadInfoV0
Metadata about a payload (node output or run outputs).
PollUntilOptions
Configuration for polling with backoff.
RequestContext
Common request metadata shared by all telemetry events.
Response
Aggregated response returned by POST /responses.
ResponseBuilder
Builder for POST /responses (async).
ResponseOptions
Optional headers for POST /responses calls.
ResponseStreamAdapter
Adapter that yields only text deltas from a stream handle.
ResponsesClient
Async client for POST /responses.
RetryConfig
Retry/backoff configuration (defaults use 3 attempts + jittered exponential backoff).
RetryMetadata
Retry metadata surfaced on transport/API errors when retries were attempted.
RunEventEnvelope
Common envelope fields for all run events.
RunEventStreamHandlestreaming
RunEventV0
A run event with envelope metadata and payload.
RunsClient
RunsCreateResponse
RunsGetResponse
RunsToolCallV0
RunsToolResultItemV0
RunsToolResultsRequest
RunsToolResultsResponse
SecretKey
SessionsClient
Client for session operations.
StreamEvent
Single SSE event emitted by the streaming proxy.
StreamFirstTokenMetrics
Time from request start to the first streaming token/event.
StreamHandlestreaming
Streaming handle over NDJSON response events.
StreamTimeoutError
Typed error for streaming timeouts.
StructuredDecodeError
Error returned when structured output fails on first attempt (before retries).
StructuredExhaustedError
Error returned when all retry attempts are exhausted.
StructuredJSONEvent
Structured JSON event (parsed from NDJSON envelope).
StructuredJSONStreamstreaming
Helper over NDJSON streaming events to yield structured JSON payloads.
StructuredOptions
Options for structured output requests.
StructuredResult
Result of a successful structured output request.
Tier
TierCheckoutRequest
Request to create a tier checkout session (checkout-first flow). Stripe collects the customer’s email during checkout.
TierCheckoutSession
Tier checkout session response.
TierModel
A model with cost information in a tier. Customer prices are derived from model costs: price = cost * (1 + platformFeePercent/100).
TiersClient
Client for tier querying operations.
TokenUsageMetrics
Token usage surfaced once a request/stream finishes.
Tool
A tool available for the model to call.
ToolCall
A tool call made by the model.
ToolCallDelta
Incremental update to a tool call during streaming.
ToolChoice
Controls how the model responds to tool calls.
ToolExecutionV1
TransformJsonInputV1
TransformJsonValueV1
TransportError
Transport-level error (timeouts, DNS/TLS/connectivity).
Usage
Token usage metadata.
UsageSummary
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).
ValidationError
Structured validation/build error returned by the SDK.
ValidationIssue
A single field-level validation issue.
WebToolConfig
Web tool configuration.
WorkflowBuilderV1
WorkflowSpecV1
Workflow specification (v1).
WorkflowValidationError
Typed workflow validation error surfaced by the SDK.
WorkflowValidationIssue
Workflow semantic validation error returned by the API compiler (/workflows/compile).
WorkflowsClient
WorkflowsCompileResponseV1
XSearchConfig
X/Twitter search configuration.

Enums§

ApiKey
ConditionOpV1
Condition operator for workflow.v1 edges.
ConditionSourceV1
Condition source for workflow.v1 edges.
ContentPart
Content part within a message (currently only text).
EnvelopeVersion
Envelope version for run events. Schema specifies const “v2”.
Error
Unified error type surfaced by the SDK.
InputItem
Input item sent to /responses.
LlmResponsesBindingEncodingV1
LocalToolError
Error type for local tool pack operations.
NodeTypeV1
Node type within a workflow.v1.
OutputFormatKind
Supported output format types.
OutputItem
Output item returned by /responses.
PollResult
Outcome of a polling attempt.
PriceInterval
Billing interval for a tier.
RunEventPayload
Event-specific payload data.
RunEventTypeV0
Run event type discriminator.
StopReason
Stop reason returned by the backend and surfaced by /responses.
StreamEventKind
High-level streaming event kinds emitted by the API.
StreamTimeoutKind
Which streaming timeout triggered.
StructuredError
Unified error type for structured output operations.
StructuredErrorKind
Specific kind of structured output error.
StructuredRecordKind
Kind of structured record.
SubscriptionStatusKind
Subscription status for billing integrations.
ToolChoiceType
Tool choice type.
ToolExecutionModeV1
ToolType
Tool type identifiers.
TransportErrorKind
Broad transport error kinds for classification.
WebToolIntent
Web tool intent (user-facing).
WorkflowKind
Workflow specification version.
WorkflowsCompileResultV1

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§

MessageRoleExt
Extension trait for MessageRole providing convenience methods.
RetryHandler
Handler for customizing retry behavior on validation failures.
TokenProvider
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 OutputFormat with 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§

LocalBashOption
Configuration options for the local bash tool pack.
LocalFSOption
Configuration options for the local filesystem tool pack.