Skip to main content

Crate adk_model

Crate adk_model 

Source
Expand description

§adk-model

LLM provider clients for ADK-Rust. Every client implements adk_core::Llm, so agents and runners accept any of them.

§Providers

ClientProviderFeature
GeminiModelGoogle Gemini (AI Studio, Vertex AI with gemini-vertex)gemini (default)
OpenAIClientOpenAI Chat Completionsopenai
openai::OpenAIResponsesClientOpenAI Responses APIopenai
AzureOpenAIClientAzure OpenAIopenai
OpenAICompatibleAny OpenAI-compatible endpoint, with presets for xAI, Fireworks AI, Together AI, Mistral AI, Perplexity, Cerebras, SambaNova, OrcaRouter, Vultr Serverless Inference, API Route, MiniMax, Zhipu AI, Baidu, Cohere, ByteDance, and Geminiopenai
AnthropicClientAnthropic Claudeanthropic
DeepSeekClientDeepSeekdeepseek
GroqClientGroqgroq
MuseClientMeta Muse Sparkmuse
OllamaModelOllama (local)ollama
OpenRouterClientOpenRouter, with its native chat, responses, routing, discovery, and credits APIsopenrouter
OpenCodeClientOpenCode Go and Zenopencode
BedrockClientAmazon Bedrockbedrock
AzureAIClientAzure AI Inferenceazure-ai
FallbackLlmAn ordered chain of any of the above, each tried when the one before it failsalways
ScriptedLlmTest double that answers each call with the next scripted reply and records every requestalways
MockLlmTest double that replays the same responses on every callalways

Transport and option features add to a provider:

FeatureEnables
gemini-interactionsGeminiModel::use_interactions_api, the Gemini Interactions API transport (Beta)
openai-wsThe Responses API WebSocket transport (WsTransport)
openai-conversationsThe Conversations API client (ConversationsClient)
openai-responses-fullopenai-ws and openai-conversations
muse-responsesMuseApi::Responses through the Open Responses engine; implies muse and openai
muse-realtimeMuseRealtimeAsrClient, live transcription over Meta’s realtime WebSocket; implies muse
all-providersgemini, openai, anthropic, deepseek, ollama, groq, muse, openrouter, opencode, bedrock and azure-ai

catalog holds the recommended model per provider and the lifecycle of known model IDs; pricing::PricingCatalog prices usage for every provider.

§Quick start

use adk_core::{Content, Llm, LlmRequest};
use adk_model::GeminiModel;
use futures::StreamExt;

let model = GeminiModel::new(std::env::var("GOOGLE_API_KEY")?, "gemini-3.8-flash")?;
let request = LlmRequest::new(
    "gemini-3.8-flash",
    vec![Content::new("user").with_text("Name one planet in a short sentence.")],
);

let mut responses = model.generate_content(request, false).await?;
while let Some(response) = responses.next().await {
    if let Some(content) = response?.content {
        for part in &content.parts {
            if let Some(text) = part.text() {
                print!("{text}");
            }
        }
    }
}

§Other providers

Each client is built from its config and used the same way:

use adk_model::anthropic::{AnthropicClient, AnthropicConfig};
use adk_model::deepseek::DeepSeekClient;
use adk_model::openai::{OpenAIClient, OpenAIConfig, OpenAIResponsesClient, OpenAIResponsesConfig};
use adk_model::{OpenAICompatible, OpenAICompatibleConfig};

let chat = OpenAIClient::new(OpenAIConfig::new("sk-...", "gpt-6.1-sol"))?;
let responses = OpenAIResponsesClient::new(OpenAIResponsesConfig::new("sk-...", "gpt-6.1-sol"))?;
let claude = AnthropicClient::new(AnthropicConfig::new("sk-ant-...", "claude-sonnet-5-5"))?;
let deepseek = DeepSeekClient::v4_flash("sk-...")?;
let grok = OpenAICompatible::new(OpenAICompatibleConfig::xai("xai-...", "grok-4.7"))?;

§Test doubles

use adk_core::{Content, Llm, LlmRequest};
use adk_model::{ScriptedLlm, ScriptedResponse};
use futures::StreamExt;

let model = ScriptedLlm::new("scripted", vec![ScriptedResponse::text("Mars.")]);
let request = LlmRequest::new("scripted", vec![Content::new("user").with_text("Name a planet.")]);

let response = model.generate_content(request, false).await?.next().await.ok_or("no response")??;
assert_eq!(response.content.unwrap().parts[0].text(), Some("Mars."));
assert_eq!(model.requests().len(), 1);

§OpenRouter scope boundary

OpenRouterClient’s native methods cover model discovery and credits, exact chat and responses payloads, routing and fallback, plugins, and built-in tools. Its adk_core::Llm adapter covers streaming, reasoning parts, tool calling, and multimodal requests, takes OpenRouter tuning through openrouter::OpenRouterRequestOptions, and maps responses into the generic adk_core::LlmResponse shape.

Re-exports§

pub use anthropic::AnthropicClient;
pub use azure_ai::AzureAIClient;
pub use azure_ai::AzureAIConfig;
pub use bedrock::BedrockClient;
pub use bedrock::BedrockConfig;
pub use deepseek::DeepSeekClient;
pub use deepseek::DeepSeekConfig;
pub use fallback::FallbackLlm;
pub use fallback::FallbackLlmBuilder;
pub use fallback::FallbackTrigger;
pub use gemini::GeminiModel;
pub use groq::GroqClient;
pub use groq::GroqConfig;
pub use http_timeouts::HttpTimeouts;
pub use mock::MockLlm;
pub use muse::FileObject;
pub use muse::ImageData;
pub use muse::ImageOptions;
pub use muse::ImagesResponse;
pub use muse::MuseApi;
pub use muse::MuseAsrClient;
pub use muse::MuseClient;
pub use muse::MuseConfig;
pub use muse::MuseFilesClient;
pub use muse::MuseImagesClient;
pub use muse::MuseResponsesClient;
pub use muse::ResponseObject;
pub use muse::ResponseRequest;
pub use muse::TranscribeOptions;
pub use muse::Transcript;
pub use muse::TranscriptSegment;
pub use ollama::OllamaConfig;
pub use ollama::OllamaModel;
pub use openai::AzureConfig;
pub use openai::AzureOpenAIClient;
pub use openai::OpenAIClient;
pub use openai::OpenAIConfig;
pub use openai::OpenAIResponsesClient;
pub use openai::OpenAIResponsesConfig;
pub use openai::ReasoningEffort;
pub use openai_compatible::OpenAICompatible;
pub use openai_compatible::OpenAICompatibleConfig;
pub use openai_compatible::ReasoningReplayField;
pub use opencode::OpenCodeApi;
pub use opencode::OpenCodeClient;
pub use opencode::OpenCodeConfig;
pub use opencode::OpenCodeService;
pub use openrouter::OpenRouterApiMode;
pub use openrouter::OpenRouterClient;
pub use openrouter::OpenRouterConfig;
pub use pricing::PricingCatalog;
pub use provider::ModelProvider;
pub use retry::RetryConfig;
pub use retry::ServerRetryHint;
pub use scripted::SCRIPT_EXHAUSTED_CODE;
pub use scripted::ScriptedLlm;
pub use scripted::ScriptedResponse;

Modules§

anthropic
Anthropic/Claude provider implementation for ADK.
azure_ai
Azure AI Inference provider for ADK.
bedrock
Amazon Bedrock provider implementation for ADK.
catalog
Curated provider model catalog, lifecycle metadata, and recommended defaults. Curated model identifiers, lifecycle metadata, and provider defaults.
deepseek
DeepSeek provider implementation for ADK.
fallback
A provider-neutral fallback chain: an ordered list of models, each tried when the one before it fails.
gemini
Gemini model provider (Google AI Studio and Vertex AI).
groq
Groq provider implementation for ADK.
http_timeouts
Connect and idle timeouts for the HTTP transport of model clients. Connect and idle timeouts for the HTTP transport of model clients.
mock
Mock LLM for testing without real API calls.
muse
Meta Muse provider implementation for ADK.
ollama
Ollama local LLM provider implementation for ADK.
openai
OpenAI provider implementation for ADK.
openai_compatible
Shared OpenAI-compatible provider implementation.
opencode
OpenCode Go and Zen integration using the existing protocol clients.
openrouter
OpenRouter provider implementation for ADK.
part_conversion
Conversion outcomes for content parts sent to a provider. What happened to each content part on the way to a provider.
pricing
Token prices for every provider and cost calculation from UsageMetadata, plus per-unit prices for models billed per image, per second of audio or per character.
provider
Canonical provider identifiers and metadata.
retry
Retry logic with exponential backoff for transient provider errors.
scripted
Scripted LLM test double with per-call replies and request capture. A scripted Llm for tests: one scripted reply per call, with every request recorded.
telemetry
OpenTelemetry GenAI inference spans for every provider client.
tool_call_parser
Text-based tool call parser for models that emit tool calls as text tags.
usage_tracking
Stream wrappers that attribute, price and record token usage.