ai() API
LLM provider, model, media, routing, and embedding APIs.
Most Used
ai
Create a provider client from a named deployment profile and options.
| Field | Value |
|---|---|
| Kind | function |
| Ax concept | ai |
| API section | AxAI |
| Form | ai(provider, options) |
| Returns | AxResult |
Important Options
api key or credential providermodelapi URLheaderstransport
Examples
let client = ai("openai", json!({"apiKey": std::env::var("OPENAI_API_KEY")?}))?;OpenAICompatibleClient
OpenAI-compatible chat, stream, embedding, audio, and realtime provider boundary.
| Field | Value |
|---|---|
| Kind | type |
| Ax concept | OpenAICompatibleClient |
| API section | AxAI |
| Form | OpenAICompatibleClient / ai(provider, options) |
| Returns | provider client |
Important Options
api keymodelbase URLtransport
OpenAIResponsesClient
OpenAI Responses provider mapping using the same Core-owned request and response contract.
| Field | Value |
|---|---|
| Kind | type |
| Ax concept | OpenAIResponsesClient |
| API section | AxAI |
| Form | OpenAIResponsesClient / ai(provider, options) |
| Returns | provider client |
Important Options
api keymodelaudiorealtime
GoogleGeminiClient
Gemini provider mapping for chat, streaming, media, tools, embeddings, and usage normalization.
| Field | Value |
|---|---|
| Kind | type |
| Ax concept | GoogleGeminiClient |
| API section | AxAI |
| Form | GoogleGeminiClient / ai(provider, options) |
| Returns | provider client |
Important Options
api keymodelembed model
AnthropicClient
Anthropic provider mapping for messages, thinking, cache control, streaming, and usage normalization.
| Field | Value |
|---|---|
| Kind | type |
| Ax concept | AnthropicClient |
| API section | AxAI |
| Form | AnthropicClient / ai(provider, options) |
| Returns | provider client |
Important Options
api keymodelthinkingcache control
AxBalancer
Retry and route requests across multiple provider services, with opt-in adaptive cost, reliability, and deadline routing.
| Field | Value |
|---|---|
| Kind | type |
| Ax concept | AxBalancer |
| API section | AxAI |
| Form | AxBalancer |
| Returns | AI service |
Important Options
servicesretry policycapability requirementsadaptive strategy
MultiServiceRouter
Choose a service by capability or model routing policy.
| Field | Value |
|---|---|
| Kind | type |
| Ax concept | MultiServiceRouter |
| API section | AxAI |
| Form | MultiServiceRouter |
| Returns | AI service |
Important Options
servicesrouting
ProviderRouter
Route requests by capability, preserving native media for supporting providers and degrading only when required.
| Field | Value |
|---|---|
| Kind | type |
| Ax concept | ProviderRouter |
| API section | AxAI |
| Form | ProviderRouter |
| Returns | AI service |
Important Options
providersroutingprocessing
Advanced / internals / full reference
typesafe
Create the native Typesafe/Jev client separately from ordinary AI services. Default model: jev-latest.
| Field | Value |
|---|---|
| Kind | function |
| Ax concept | typesafe |
| API section | AxAI |
| Form | typesafe(options) |
| Returns | AxAITypesafeClient |
Important Options
api key or credential providerendpointtransporttimeoutretry
AxAITypesafeClient
Native System One questions and model discovery. Returns typed Noul probabilities, Choice labels, fractional Score positions, model, and usage.
| Field | Value |
|---|---|
| Kind | type |
| Ax concept | AxAITypesafeClient |
| API section | AxAI |
| Form | AxAITypesafeClient |
| Returns | native Typesafe responses |
Important Options
system_one / systemOne / SystemOnelist_models / listModels / ListModelsstructured or null entriescancellation
AxCancellationToken
Reusable one-shot cancellation for provider calls, streams, retries, and event-clock sleeps. Go uses context.Context.
| Field | Value |
|---|---|
| Kind | type |
| Ax concept | AxCancellationToken |
| API section | AxAI |
| Form | AxCancellationToken::default() |
| Returns | cancellation token or context |
Important Options
first reason winsremovable wake subscriptionsnon-retryable cancellation
AxAIServiceAbortedError
Terminal provider error raised when caller cancellation is observed.
| Field | Value |
|---|---|
| Kind | error |
| Ax concept | AxAIServiceAbortedError |
| API section | AxAI |
| Form | AxError with error_type AxAIServiceAbortedError |
| Returns | non-retryable provider error |
Important Options
reason preservationno retryno provider failover
get_supported_ai_models
Return the AxIR-backed provider and model catalog, including dynamic named profiles and portable capability metadata.
| Field | Value |
|---|---|
| Kind | function |
| Ax concept | get_supported_ai_models |
| API section | AxAI |
| Form | get_supported_ai_models() / get_supported_ai_models_with_options(options) |
| Returns | AxResult<Vec<serde_json::Value» |
Important Options
type filterthinkingLevelsserviceTiersisDynamic
Examples
let catalog = get_supported_ai_models()?;AxCredentialRequest
Request metadata passed to a renewable credential callback for every transport attempt.
| Field | Value |
|---|---|
| Kind | type |
| Ax concept | AxCredentialRequest |
| API section | AxAI |
| Form | AxCredentialRequest |
| Returns | credential request |
Important Options
profileoperationmethodURL
AxCredentialProvider
Return fresh request headers that override static profile authentication.
| Field | Value |
|---|---|
| Kind | interface |
| Ax concept | AxCredentialProvider |
| API section | AxAI |
| Form | dyn AxCredentialProvider |
| Returns | header map or credential error |
Important Options
chatstreamembeddingsResponsesaudioretries
AxAIClient::owned_worker_factory
Optional factory for an independent client worker with preserved configuration, authentication and routing. Built-in providers supply it; custom services may omit it without changing chat compatibility.
| Field | Value |
|---|---|
| Kind | method |
| Ax concept | owned_client_factory |
| API section | AxAI |
| Form | AxAIClient::owned_worker_factory() |
| Returns | worker factory or unavailable |
Important Options
owned configurationshared balancer accountingno borrowed client transfer
AxChatSession
Optional normalized session capability for custom provider adapters. High-level programs own tool execution and continuation; chat-only services remain supported.
| Field | Value |
|---|---|
| Kind | interface |
| Ax concept | AxChatSession |
| API section | AxAI |
| Form | AxChatSession |
| Returns | run-owned chat session |
Important Options
normalized eventscompleted callssubmit resultssteeringreasoning updatesclose
AxChatStream
Incremental, closeable provider event stream. Retry and failover stop once content is delivered.
| Field | Value |
|---|---|
| Kind | type |
| Ax concept | AxProviderStream |
| API section | AxAI |
| Form | client.stream_iter(request) |
| Returns | incremental chat events |
Important Options
next eventterminal errorconsumer cancellationupstream close
Examples
for event in client.stream_iter(request)? { handle(event?); }AxUsageContext
Application attribution merged from service defaults and per-call overrides.
| Field | Value |
|---|---|
| Kind | type |
| Ax concept | AxUsageContext |
| API section | AxAI |
| Form | AxUsageContext |
| Returns | usage context |
Important Options
tenantuserrequestrunfeatureattributes
AxUsageEvent
Normalized token usage and correlation data for one completed chat or embedding operation.
| Field | Value |
|---|---|
| Kind | type |
| Ax concept | AxUsageEvent |
| API section | AxAI |
| Form | AxUsageEvent |
| Returns | usage event |
Important Options
providermodeltokenscontextcorrelation IDsstreaming
AxUsageObserver
Best-effort process-wide callback for normalized usage events.
| Field | Value |
|---|---|
| Kind | interface |
| Ax concept | AxUsageObserver |
| API section | AxAI |
| Form | AxUsageObserver |
| Returns | usage observer |
Important Options
fail-open deliverysynchronous enqueue
set_usage_observer
Register, replace, or clear the process-wide usage observer.
| Field | Value |
|---|---|
| Kind | function |
| Ax concept | set_usage_observer |
| API section | AxAI |
| Form | set_usage_observer(observer) |
| Returns | void |
Important Options
observerclear
Examples
set_usage_observer(Some(Arc::new(move |event| events.lock().unwrap().push(event))));AxRuntimeHooks
Non-serializable rate limiter, tracer, and meter overrides for one service or program execution.
| Field | Value |
|---|---|
| Kind | type |
| Ax concept | AxRuntimeHooks |
| API section | AxAI |
| Form | AxRuntimeHooks |
| Returns | runtime hooks |
Important Options
rate limitertracermeterprecedence
Examples
let hooks = AxRuntimeHooks::new().rate_limiter(limiter).tracer(tracer).meter(meter);AxRateLimitInfo
Provider and model metadata supplied to a request-wrapper rate limiter.
| Field | Value |
|---|---|
| Kind | type |
| Ax concept | AxRateLimitInfo |
| API section | AxAI |
| Form | AxRateLimitInfo |
| Returns | rate-limit context |
Important Options
operationprovidermodelstreamingprevious usage
AxRateLimiter
Request wrapper that can delay, reject, or execute a chat or embedding request.
| Field | Value |
|---|---|
| Kind | interface |
| Ax concept | AxRateLimiter |
| API section | AxAI |
| Form | AxRateLimiter |
| Returns | provider result |
Important Options
nextmetadataerrors
AxTracer
Dependency-neutral tracer that creates metadata-only Ax spans.
| Field | Value |
|---|---|
| Kind | interface |
| Ax concept | AxTracer |
| API section | AxAI |
| Form | AxTracer |
| Returns | span |
Important Options
start spanparent spanfail-open
AxMeter
Dependency-neutral meter for Ax counters, histograms, and gauges.
| Field | Value |
|---|---|
| Kind | interface |
| Ax concept | AxMeter |
| API section | AxAI |
| Form | AxMeter |
| Returns | instrument |
Important Options
counterhistogramgaugefail-open
AxGlobals
Process-wide live defaults for runtime hooks and usage observation.
| Field | Value |
|---|---|
| Kind | type |
| Ax concept | AxGlobals |
| API section | AxAI |
| Form | AxGlobals |
| Returns | global hooks |
Important Options
rate limitertracermeterusage observer
set_rate_limiter
Register, replace, or clear the process-wide request-wrapper rate limiter.
| Field | Value |
|---|---|
| Kind | function |
| Ax concept | set_rate_limiter |
| API section | AxAI |
| Form | set_rate_limiter(limiter) |
| Returns | void |
Important Options
limiterclear
Examples
set_rate_limiter(Some(limiter));set_tracer
Register, replace, or clear the process-wide dependency-neutral tracer.
| Field | Value |
|---|---|
| Kind | function |
| Ax concept | set_tracer |
| API section | AxAI |
| Form | set_tracer(tracer) |
| Returns | void |
Important Options
tracerclear
Examples
set_tracer(Some(tracer));set_meter
Register, replace, or clear the process-wide dependency-neutral meter.
| Field | Value |
|---|---|
| Kind | function |
| Ax concept | set_meter |
| API section | AxAI |
| Form | set_meter(meter) |
| Returns | void |
Important Options
meterclear
Examples
set_meter(Some(meter));AxBalancerAdaptiveStrategy
Configure adaptive provider routing without changing the ordered default.
| Field | Value |
|---|---|
| Kind | type |
| Ax concept | AxBalancerAdaptiveStrategy |
| API section | AxAI |
| Form | AxBalancerAdaptiveStrategy |
| Returns | adaptive strategy |
Important Options
deadlinebad outcome costexpected tokensstable route keysslicestats storerouting events
AxBalancerStatsStore
Store shared adaptive decision state with atomic observations.
| Field | Value |
|---|---|
| Kind | interface |
| Ax concept | AxBalancerStatsStore |
| API section | AxAI |
| Form | AxBalancerStatsStore |
| Returns | stats store |
Important Options
getobserve
AxInMemoryBalancerStatsStore
Thread-safe in-memory adaptive stats store.
| Field | Value |
|---|---|
| Kind | type |
| Ax concept | AxInMemoryBalancerStatsStore |
| API section | AxAI |
| Form | AxInMemoryBalancerStatsStore |
| Returns | stats store |
create_balancer_route_stats
Create neutral adaptive route statistics.
| Field | Value |
|---|---|
| Kind | function |
| Ax concept | create_balancer_route_stats |
| API section | AxAI |
| Form | create_balancer_route_stats |
| Returns | route stats |
update_balancer_route_stats
Purely reduce one success or failure observation into route statistics.
| Field | Value |
|---|---|
| Kind | function |
| Ax concept | update_balancer_route_stats |
| API section | AxAI |
| Form | update_balancer_route_stats |
| Returns | route stats |
Important Options
current statsobservation
sample_balancer_route_health
Sample failure and deadline-miss probability for adaptive exploration.
| Field | Value |
|---|---|
| Kind | function |
| Ax concept | sample_balancer_route_health |
| API section | AxAI |
| Form | sample_balancer_route_health |
| Returns | sampled health |
Important Options
route statsdeadline
Full Reference
Open the full Rust reference. This page highlights the ai symbols most relevant to everyday use.