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::DeviceStartResponse;
pub use customers::SubscriptionStatus;
pub use generated::RunsPendingToolCallV0;
pub use generated::RunsPendingToolsNodeV0;
pub use generated::RunsPendingToolsResponse;
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.
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.
CheckoutSession
Checkout session response.
CheckoutSessionRequest
Request to create a checkout session.
Client
Async client for the ModelRelay API.
ClientBuilder
Builder for constructing a Client with explicit configuration.
CodeExecConfig
Code execution configuration.
Config
Configuration for the async ModelRelay client.
Customer
A customer in a ModelRelay project.
CustomerClaimRequest
Request to link an end-user identity (provider + subject) to a customer by email.
CustomerCreateRequest
Request to create a customer.
CustomerToken
Short-lived bearer token usable from browser/mobile clients.
CustomerTokenRequest
Request payload for POST /auth/customer-token.
CustomerUpsertRequest
Request to upsert a customer by external_id.
CustomersClient
Client for customer management operations.
DateTime
ISO 8601 combined date and time with time zone.
DefaultRetryHandler
Default retry handler that appends a simple error correction message.
DeviceAuthConfig
Configuration for starting OAuth device authorization.
DeviceAuthorization
Result of device authorization request.
DevicePollConfig
Configuration for polling the device token endpoint.
DeviceStartRequest
Request options for starting a device authorization flow.
DeviceToken
Result of successful device token poll.
DeviceTokenPending
Pending state when user hasn’t completed authorization yet.
DeviceTokenResponse
Successful token response from device flow.
EdgeV0
An edge connecting two nodes in the workflow DAG.
ExecutionV0
Execution configuration for a workflow.
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.
HeaderEntry
HeaderList
Structured header/metadata list with validation.
HttpRequestMetrics
HTTP request latency and outcome.
JSONSchemaFormat
JSON schema payload for structured outputs.
LlmResponsesBindingV0
MetricsCallbacks
User-provided callbacks for emitting metrics without taking on a tracing dependency.
Model
Model identifier (string wrapper).
ModelsClient
Client for model catalog operations.
NodeResultV0
Result of a completed node.
NodeV0
A node in the workflow DAG.
OIDCExchangeConfig
Configuration for OIDCExchangeTokenProvider.
OIDCExchangeTokenProvider
Token provider that exchanges OIDC id_tokens for customer bearer tokens.
OutputFormat
Output format configuration (structured outputs).
OutputRefV0
Reference to a workflow output.
PayloadInfoV0
Metadata about a payload (node output or run outputs).
PublishableKey
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
SecretKey
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.
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 (Stripe-first flow). Stripe collects the customer’s email during checkout.
TierCheckoutSession
Tier checkout session response.
TierModel
A pricing tier in a ModelRelay project.
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.
TransformJsonInputV0
TransformJsonValueV0
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.
WorkflowBuilderV0
WorkflowSpecV0
Workflow specification (v0).
WorkflowValidationError
Typed workflow validation error surfaced by the SDK.
WorkflowValidationIssue
Workflow semantic validation error returned by the API compiler (/workflows/compile).
WorkflowsClient
WorkflowsCompileResponseV0
XSearchConfig
X/Twitter search configuration.

Enums§

ApiKey
ContentPart
Content part within a message (currently only text).
DeviceFlowErrorKind
Typed error kinds for device flow failures.
DeviceFlowProvider
Provider for native device authorization flow.
DeviceTokenResult
Result of polling the device token endpoint.
EnvelopeVersion
Envelope version for run events. Schema specifies const “v0”.
Error
Unified error type surfaced by the SDK.
InputItem
Input item sent to /responses.
LlmResponsesBindingEncodingV0
NodeTypeV0
Node type within a workflow.
OutputFormatKind
Supported output format types.
OutputItem
Output item returned by /responses.
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.
StructuredError
Unified error type for structured output operations.
StructuredErrorKind
Specific kind of structured output error.
StructuredRecordKind
Kind of structured record.
SubscriptionStatusKind
Subscription status values (matches Stripe subscription statuses).
ToolChoiceType
Tool choice type.
ToolType
Tool type identifiers.
TransportErrorKind
Broad transport error kinds for classification.
WorkflowKind
Workflow specification version.
WorkflowsCompileResultV0

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).
REQUEST_ID_HEADER
HTTP header name for request ID tracing.
RUN_EVENT_V0_SCHEMA_JSON
JSON Schema for run_event.v0 events.
WORKFLOW_V0_SCHEMA_JSON
JSON Schema for workflow.v0 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§

output_format_from_type
Generates an OutputFormat with automatic JSON schema from a type.
poll_device_token
Poll for OAuth device token until authorized or timeout.
run_device_flow_for_id_token
Run complete OAuth device flow and return the id_token.
run_node_ref
Creates a reference string for a node within a run.
start_device_authorization
Start OAuth device authorization flow.
workflow_v0

Type Aliases§

CatalogModel
CatalogModel is the model catalog entry returned by GET /models.
CustomerMetadata
Customer metadata as a key-value map.
IdTokenSource
Type alias for async id_token provider functions.