ai() API
LLM provider, model, media, routing, and embedding APIs.
Most Used
ai
Create a provider client from a provider name and options.
| Field | Value |
|---|---|
| Kind | function |
| Ax concept | ai |
| API section | AxAI |
| Form | ai(provider, options) |
| Returns | AxResult |
Important Options
api keymodelapi 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 provider requests to registered provider clients.
| Field | Value |
|---|---|
| Kind | type |
| Ax concept | ProviderRouter |
| API section | AxAI |
| Form | ProviderRouter |
| Returns | AI service |
Important Options
providersroutingprocessing
Advanced / internals / full reference
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))));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.