#![cfg_attr(docsrs, feature(doc_cfg))]
#![allow(clippy::result_large_err)]
pub mod generated;
pub const DEFAULT_BASE_URL: &str = "https://api.modelrelay.ai/api/v1";
pub(crate) const DEFAULT_CLIENT_HEADER: &str =
concat!("modelrelay-rust/", env!("CARGO_PKG_VERSION"));
pub const DEFAULT_CONNECT_TIMEOUT: std::time::Duration = std::time::Duration::from_secs(5);
pub const DEFAULT_REQUEST_TIMEOUT: std::time::Duration = std::time::Duration::from_secs(60);
pub const REQUEST_ID_HEADER: &str = "X-ModelRelay-Request-Id";
pub(crate) const API_KEY_HEADER: &str = "X-ModelRelay-Api-Key";
mod api_key;
mod bash_policy;
mod bash_tokenizer;
#[cfg(feature = "billing")]
mod billing;
mod client;
mod convenience;
mod core;
mod errors;
mod http;
mod identifiers;
mod images;
mod local_bash_tools;
mod local_fs_tools;
mod local_tools_common;
#[cfg(feature = "mock")]
mod mock;
mod plugins;
mod responses;
mod runs;
mod sessions;
mod sql;
mod sql_tool_loop;
mod state_handles;
mod structured;
mod telemetry;
pub mod testing;
mod tiers;
mod token_providers;
pub mod tools;
mod types;
mod workflow;
mod workflow_intent;
mod workflow_intent_builder;
mod workflows;
pub mod wrapper_v1;
pub use chrono::{DateTime, Utc};
pub use uuid::Uuid;
pub use api_key::{ApiKey, SecretKey};
#[cfg(feature = "billing")]
pub use billing::BillingClient;
pub use errors::{
APIError, Error, FieldError, RetryMetadata, StreamTimeoutError, StreamTimeoutKind,
TransportError, TransportErrorKind, ValidationError, WorkflowValidationError,
WorkflowValidationIssue,
};
pub use http::{HeaderEntry, HeaderList, ResponseOptions, RetryConfig};
#[cfg(all(feature = "mock", feature = "blocking"))]
pub use mock::MockBlockingResponsesClient;
#[cfg(feature = "mock")]
pub use mock::{fixtures, MockAuthClient, MockClient, MockConfig, MockResponsesClient};
#[cfg(all(feature = "blocking", feature = "streaming"))]
pub use responses::BlockingStructuredJSONStream;
#[cfg(feature = "streaming")]
pub use responses::StructuredJSONStream;
pub use responses::{
get_all_tool_calls_from_response, BatchOptions, BatchRequestItem, ResponseBuilder,
ResponseStreamAdapter, ToolResultItem, CUSTOMER_ID_HEADER,
};
pub use responses::{StructuredJSONEvent, StructuredRecordKind};
pub use sql_tool_loop::{
SqlColumnInfo, SqlExecuteResult, SqlRow, SqlTableDescription, SqlTableInfo, SqlToolLoopBuilder,
SqlToolLoopHandlers, SqlToolLoopOptions, SqlToolLoopResult,
};
pub use telemetry::{
HttpRequestMetrics, MetricsCallbacks, RequestContext, StreamFirstTokenMetrics,
TokenUsageMetrics,
};
pub use tools::{
assistant_message_with_tool_calls, create_retry_messages, execute_with_retry,
format_tool_error_for_model, get_retryable_errors, has_retryable_errors, is_user_ask_tool_call,
parse_and_validate_tool_args, parse_tool_args, parse_user_ask_args, respond_to_tool_call,
respond_to_tool_call_json, serialize_user_ask_result, sync_handler, tool_result_message,
tool_result_message_json, user_ask_result_choice, user_ask_result_freeform, user_ask_tool,
BoxFuture, ParseResult, ResponseExt, RetryOptions, ToolArgsError, ToolBuilder,
ToolCallAccumulator, ToolExecutionResult, ToolHandler, ToolRegistry, TypedTool, TypedToolCall,
UnknownToolError, UserAskArgs, UserAskOption, UserAskResponse, ValidateArgs,
USER_ASK_TOOL_NAME,
};
pub use tools::{function_tool_from_type, ToolSchema};
pub use convenience::{
AgentOptions, AgentResult, AgentUsage, ChatOptions, DEFAULT_MAX_TURNS, NO_TURN_LIMIT,
};
pub use types::{
APIKey, BatchError, BatchResponse, BatchResult, BatchStatus, BatchUsage, Citation,
CodeExecConfig, ContentPart, CustomerToken, CustomerTokenRequest, FileContent, FunctionCall,
FunctionCallDelta, FunctionTool, GetOrCreateCustomerTokenRequest, InputItem, JSONSchemaFormat,
MessageRole, MessageRoleExt, MimeType, Model, OutputFormat, OutputFormatKind, OutputItem,
Response, StopReason, StreamEvent, StreamEventKind, SubscriptionStatusKind, Tool, ToolCall,
ToolCallDelta, ToolChoice, ToolChoiceType, ToolType, Usage, UsageSummary, XSearchConfig,
};
pub use bash_policy::BashPolicy;
pub use bash_tokenizer::{tokenize_bash, BashTokens};
pub use client::{
AuthClient, Client, ClientBuilder, Config, CustomerResponsesClient, CustomerScopedClient,
ResponsesClient,
};
pub use generated::{
ImageData, ImagePinResponse, ImageRequest, ImageResponse, ImageResponseFormat, ImageUsage,
};
pub use generated::{RunsPendingToolCallV0, RunsPendingToolsResponse};
pub use generated::{
SessionCreateRequest, SessionListResponse, SessionMessageCreateRequest, SessionMessageResponse,
SessionResponse, SessionWithMessagesResponse,
};
pub use generated::{StateHandleCreateRequest, StateHandleListResponse, StateHandleResponse};
pub use generated::{ToolCallId, ToolName};
pub use identifiers::TierCode;
pub use images::ImagesClient;
pub use local_bash_tools::{
new_local_bash_tools, with_bash_allow_env_vars, with_bash_hard_max_output_bytes,
with_bash_inherit_env, with_bash_max_output_bytes, with_bash_policy, with_bash_timeout,
BashResult, LocalBashOption, LocalBashToolPack,
};
pub use local_fs_tools::{
new_local_fs_tools, with_local_fs_hard_max_list_entries, with_local_fs_hard_max_read_bytes,
with_local_fs_hard_max_search_matches, with_local_fs_ignore_dirs,
with_local_fs_max_list_entries, with_local_fs_max_read_bytes, with_local_fs_max_search_bytes,
with_local_fs_max_search_matches, with_local_fs_search_timeout, LocalFSOption, LocalFSToolPack,
};
pub use local_tools_common::LocalToolError;
pub use plugins::{
OrchestrationMode, Plugin, PluginAgent, PluginAgentName, PluginCommand, PluginCommandName,
PluginConverter, PluginConverterOptions, PluginError, PluginGitHubRef, PluginId, PluginLoader,
PluginLoaderOptions, PluginManifest, PluginOrchestrationError, PluginOrchestrationErrorCode,
PluginRunConfig, PluginRunError, PluginRunResult, PluginToolName, PluginUrl, PluginsClient,
PluginsClientOptions,
};
#[cfg(feature = "streaming")]
pub use runs::RunEventStreamHandle;
pub use runs::{
RunsClient, RunsCreateOptions, RunsCreateResponse, RunsFanoutSubnodeOverride, RunsGetResponse,
RunsModelOverrides, RunsToolCallV0, RunsToolResultItemV0, RunsToolResultsRequest,
RunsToolResultsResponse,
};
pub use sessions::{ListSessionsOptions, SessionsClient};
pub use sql::SqlClient;
pub use state_handles::{
ListStateHandlesOptions, StateHandlesClient, MAX_STATE_HANDLE_TTL_SECONDS,
};
pub use tiers::{
PriceInterval, Tier, TierCheckoutRequest, TierCheckoutSession, TierModel, TiersClient,
};
pub use workflow::{
run_node_ref, ArtifactKey, EnvelopeVersion, ModelId, NodeErrorV0, NodeId, NodeResultV0,
NodeStatusV0, NodeTypeV1, PayloadInfoV0, PlanHash, ProviderId, RequestId, RunCostLineItemV0,
RunCostSummaryV0, RunEventEnvelope, RunEventPayload, RunEventTypeV0, RunEventV0, RunId,
RunStatusV0, Sha256Hash, LLM_TEXT_OUTPUT, LLM_USER_MESSAGE_TEXT, RUN_EVENT_V0_SCHEMA_JSON,
};
pub use workflow_intent::{
IntentKind, IntentSpec, WorkflowIntentCondition, WorkflowIntentInputDecl, WorkflowIntentKind,
WorkflowIntentNode, WorkflowIntentNodeType, WorkflowIntentOutputRef, WorkflowIntentSpec,
WorkflowIntentToolExecution, WorkflowIntentToolExecutionMode, WorkflowIntentToolRef,
WorkflowIntentTransformValue,
};
pub use workflow_intent_builder::{
chain, llm, parallel, workflow, workflow_intent, ChainOptions, JoinCollectOptions,
LLMNodeBuilder, MapFanoutOptions, ParallelOptions, WorkflowIntentBuilder,
};
pub use workflows::{WorkflowsClient, WorkflowsCompileResponse, WorkflowsCompileResult};
pub use structured::{
output_format_from_type, AttemptRecord, DefaultRetryHandler, RetryHandler,
StructuredDecodeError, StructuredError, StructuredErrorKind, StructuredExhaustedError,
StructuredOptions, StructuredResult, ValidationIssue,
};
pub use token_providers::{
poll_until, CustomerTokenProvider, CustomerTokenProviderConfig, CustomerTokenResponse,
PollResult, PollUntilOptions, TokenProvider,
};
#[cfg(feature = "streaming")]
mod ndjson;
#[cfg(feature = "streaming")]
pub use ndjson::StreamHandle;
#[cfg(feature = "blocking")]
mod blocking;
#[cfg(all(feature = "blocking", feature = "billing"))]
pub use blocking::BlockingBillingClient;
#[cfg(all(feature = "blocking", feature = "streaming"))]
pub use blocking::BlockingRunEventStreamHandle;
#[cfg(all(feature = "blocking", feature = "streaming"))]
pub use blocking::BlockingStreamHandle;
#[cfg(feature = "blocking")]
pub use blocking::{
BlockingAuthClient, BlockingClient, BlockingConfig, BlockingResponsesClient, BlockingRunsClient,
};