adapters
ModuleThe provider adapters.
Contents
11 submodules.
adapters::anthropic
Own pageAnthropic.
use utopia_agents::Anthropic;pub struct AnthropicAnthropic's Messages API: answers streamed token by token, with token usage (prompt cache writes and reads included) counted from the stream's events; with a schema, a forced tool call whose input is the answer. The description and the first instructions (four blocks in all) are marked for prompt caching. Images attach as base64 sources.
use utopia_agents::{Adapter, Anthropic, adapters::anthropic};
let adapter = Anthropic::new("test-api-key").with_model(anthropic::MODEL_CLAUDE_4_SONNET);
assert_eq!((adapter.name(), adapter.model()), ("anthropic", "claude-sonnet-4-0"));pub const API_VERSION: &str = "2023-06-01"The API version requests ask for (anthropic-version).
pub const ENDPOINT: &str = "https://api.anthropic.com/v1/messages"The Messages API endpoint.
pub const MODEL_CLAUDE_3_5_HAIKU: &str = "claude-3-5-haiku-latest"Claude 3.5 Haiku.
pub const MODEL_CLAUDE_3_5_SONNET: &str = "claude-3-5-sonnet-latest"Claude 3.5 Sonnet.
pub const MODEL_CLAUDE_3_7_SONNET: &str = "claude-3-7-sonnet-latest"Claude 3.7 Sonnet.
pub const MODEL_CLAUDE_3_HAIKU: &str = "claude-3-haiku-20240307"Claude 3 Haiku (the default).
pub const MODEL_CLAUDE_3_OPUS: &str = "claude-3-opus-latest"Claude 3 Opus.
pub const MODEL_CLAUDE_4_OPUS: &str = "claude-opus-4-0"Claude 4 Opus.
pub const MODEL_CLAUDE_4_SONNET: &str = "claude-sonnet-4-0"Claude 4 Sonnet.
pub const MODELS: &[&str] = &[ MODEL_CLAUDE_4_OPUS, MODEL_CLAUDE_3_OPUS, MODEL_CLAUDE_4_SONNET, MODEL_CLAUDE_3_7_SONNET, MODEL_CLAUDE_3_5_SONNET, MODEL_CLAUDE_3_5_HAIKU, MODEL_CLAUDE_3_HAIKU, ]Undocumented.
adapters::appwrite
Own pageAppwrite's embedding service.
use utopia_agents::Appwrite;pub struct AppwriteEmbeddings from Appwrite's embedding service (no API key), several texts
per request. It does not chat: Adapter::send fails.
use utopia_agents::{Adapter, Appwrite, adapters::appwrite};
let adapter = Appwrite::with_model(appwrite::MODEL_ALL_MINILM)?;
assert_eq!(adapter.name(), "appwrite-embedding");
assert_eq!(adapter.embedding_dimension()?, 384);Default.use utopia_agents::adapters::appwrite::dimension;pub fn dimension(model: &str) -> Option<i64>The size of a model's embeddings.
pub const ENDPOINT: &str = "http://appwrite-embedding:11434/embed"The embed endpoint of the embedding service.
pub const MODEL_ALL_MINILM: &str = "all-minilm"all-MiniLM-L6-v2: small and fast.
pub const MODEL_BGE_SMALL: &str = "bge-small"BGE Small EN v1.5: small, English.
pub const MODEL_EMBEDDING_GEMMA: &str = "embedding-gemma"EmbeddingGemma 300M.
pub const MODEL_NOMIC_EMBED_TEXT: &str = "nomic-embed-text"Nomic Embed Text v1.5: general purpose (the default).
pub const MODELS: &[&str] = &[MODEL_NOMIC_EMBED_TEXT, MODEL_EMBEDDING_GEMMA, MODEL_ALL_MINILM, MODEL_BGE_SMALL]Every model.
adapters::chat
Own pageThe OpenAI chat completions protocol, which OpenAI, OpenRouter,
Perplexity and xAI speak, each with its own differences (Dialect).
adapters::deepseek
Own pageDeepseek.
use utopia_agents::Deepseek;pub struct DeepseekDeepseek's chat completions, always streamed, with token usage counted
from the stream. Messages without a role or any text or image are left
out. With a schema, the answer is asked for in JSON mode and the schema
is described in the system message (Schema::to_json).
use utopia_agents::{Adapter, Deepseek};
let adapter = Deepseek::new("test-api-key");
assert_eq!((adapter.name(), adapter.model()), ("deepseek", "deepseek-chat"));pub const ENDPOINT: &str = "https://api.deepseek.com/chat/completions"The chat completions endpoint.
pub const MODEL_DEEPSEEK_CHAT: &str = "deepseek-chat"Deepseek Chat (the default).
pub const MODEL_DEEPSEEK_CODER: &str = "deepseek-coder"Deepseek Coder.
pub const MODELS: &[&str] = &[MODEL_DEEPSEEK_CHAT, MODEL_DEEPSEEK_CODER]Undocumented.
adapters::gemini
Own pageGoogle Gemini.
use utopia_agents::Gemini;pub struct GeminiGoogle's Gemini API: answers always streamed (server-sent events), the
description and instructions as the system instruction, the assistant's
messages as the model role, images inline. No structured output.
use utopia_agents::{Adapter, Gemini, adapters::gemini};
let adapter = Gemini::new("test-api-key").with_model(gemini::MODEL_GEMINI_2_0_FLASH_LITE);
assert_eq!(adapter.name(), "gemini");
assert_eq!(
adapter.endpoint(),
"https://generativelanguage.googleapis.com/v1beta/models/gemini-2.0-flash-lite:streamGenerateContent?alt=sse&key=test-api-key"
);use utopia_agents::adapters::gemini::endpoint;pub fn endpoint(model: &str, api_key: &str) -> StringThe streaming endpoint of a model, with the API key in the query.
pub const MODEL_GEMINI_1_5_PRO: &str = "gemini-1.5-pro"Gemini 1.5 Pro.
pub const MODEL_GEMINI_2_0_FLASH: &str = "gemini-2.0-flash"Gemini 2.0 Flash (the default).
pub const MODEL_GEMINI_2_0_FLASH_LITE: &str = "gemini-2.0-flash-lite"Gemini 2.0 Flash Lite.
pub const MODEL_GEMINI_2_5_FLASH_PREVIEW: &str = "gemini-2.5-flash-preview-04-17"Gemini 2.5 Flash Preview.
pub const MODEL_GEMINI_2_5_PRO_PREVIEW: &str = "gemini-2.5-pro-preview-03-25"Gemini 2.5 Pro Preview.
pub const MODELS: &[&str] = &[ MODEL_GEMINI_2_0_FLASH, MODEL_GEMINI_2_0_FLASH_LITE, MODEL_GEMINI_1_5_PRO, MODEL_GEMINI_2_5_FLASH_PREVIEW, MODEL_GEMINI_2_5_PRO_PREVIEW, ]Undocumented.
adapters::ollama
Own pageOllama (embeddings).
use utopia_agents::Ollama;pub struct OllamaEmbeddings from a local Ollama service (no API key). It does not chat:
Adapter::send fails.
use utopia_agents::{Adapter, Ollama};
let adapter = Ollama::new();
assert_eq!((adapter.name(), adapter.model()), ("ollama", "embeddinggemma"));
assert_eq!(adapter.embedding_dimension()?, 768);
assert!(Ollama::with_model("unknown").is_err());Default.use utopia_agents::adapters::ollama::dimension;pub fn dimension(model: &str) -> Option<i64>The size of a model's embeddings.
pub const ENDPOINT: &str = "http://ollama:11434/api/embed"The embed endpoint of the local Ollama service.
pub const MODEL_EMBEDDING_GEMMA: &str = "embeddinggemma"EmbeddingGemma (the default and only model).
pub const MODELS: &[&str] = &[MODEL_EMBEDDING_GEMMA]Every model.
adapters::openai
Own pageOpenAI.
use utopia_agents::OpenAi;pub struct OpenAi(Chat)OpenAI's chat completions: answers streamed token by token, or, with a
schema, a JSON answer in strict json_schema mode. Images attach as
data URLs. gpt-5-nano only takes temperature 1 (another is replaced,
with a warning on standard error), and the o-series and gpt-5-nano
take max_completion_tokens instead of max_tokens.
use utopia_agents::{Adapter, OpenAi, adapters::openai};
let adapter = OpenAi::new("test-api-key").with_model(openai::MODEL_GPT_4O).with_max_tokens(2048);
assert_eq!(adapter.name(), "openai");
assert_eq!(adapter.model(), "gpt-4o");
assert_eq!(adapter.endpoint(), "https://api.openai.com/v1/chat/completions");pub const ENDPOINT: &str = "https://api.openai.com/v1/chat/completions"The chat completions endpoint.
pub const MODEL_GPT_4_1: &str = "gpt-4.1"GPT-4.1.
pub const MODEL_GPT_4_5_PREVIEW: &str = "gpt-4.5-preview"GPT-4.5 Preview.
pub const MODEL_GPT_4O: &str = "gpt-4o"GPT-4o: multimodal, text and images.
pub const MODEL_GPT_5_NANO: &str = "gpt-5-nano"GPT-5 Nano: a small GPT-5 for low latency and cost-sensitive work.
pub const MODEL_O3: &str = "o3"o3.
pub const MODEL_O3_MINI: &str = "o3-mini"o3-mini (the default).
pub const MODEL_O4_MINI: &str = "o4-mini"o4-mini.
pub const MODELS: &[&str] = &[MODEL_GPT_5_NANO, MODEL_GPT_4_5_PREVIEW, MODEL_GPT_4_1, MODEL_GPT_4O, MODEL_O4_MINI, MODEL_O3, MODEL_O3_MINI]Undocumented.
adapters::openrouter
Own pageOpenRouter.
use utopia_agents::OpenRouter;pub struct OpenRouter(Chat)OpenRouter's OpenAI-compatible chat completions, routed to any
provider's model (meta-llama/llama-3.3-70b-instruct). Structured
output is not offered: not every routed model supports it. The routed
model's provider prefix and : suffix are ignored when choosing the
token limit parameter and temperature (openai/gpt-5-nano:free is
treated as gpt-5-nano). An app URL and title, when given, go in the
HTTP-Referer and X-Title headers.
use utopia_agents::{Adapter, OpenRouter, adapters::openrouter::models};
let adapter = OpenRouter::new("test-api-key").with_app(Some("https://example.com"), Some("Example"));
assert_eq!(adapter.model(), models::MODEL_OPENAI_GPT_4O);
assert!(adapter.models().contains(&"openai/gpt-4o"));pub const ENDPOINT: &str = "https://openrouter.ai/api/v1/chat/completions"The chat completions endpoint.
adapters::openrouter::models
Own pageOpenRouter's model catalog: a named constant per model of the curated
providers (Anthropic, OpenAI, Google, Meta, Deepseek, Mistral, xAI) and
MODELS, every model id, generated from
data/openrouter-constants.txt and data/openrouter-models.txt, which
the agents-sync-openrouter-models task refreshes.
adapters::perplexity
Own pagePerplexity.
use utopia_agents::Perplexity;pub struct Perplexity(Chat)Perplexity's OpenAI-compatible chat completions. An HTML error page in
the stream (an authorization failure) becomes (http_<status>) <reason> from its title or first heading.
use utopia_agents::{Adapter, Perplexity};
let adapter = Perplexity::new("test-api-key");
assert_eq!((adapter.name(), adapter.model()), ("perplexity", "sonar"));pub const ENDPOINT: &str = "https://api.perplexity.ai/chat/completions"The chat completions endpoint.
pub const MODEL_SONAR: &str = "sonar"Sonar: lightweight search (the default).
pub const MODEL_SONAR_DEEP_RESEARCH: &str = "sonar-deep-research"Sonar Deep Research.
pub const MODEL_SONAR_PRO: &str = "sonar-pro"Sonar Pro.
pub const MODEL_SONAR_REASONING: &str = "sonar-reasoning"Sonar Reasoning.
pub const MODEL_SONAR_REASONING_PRO: &str = "sonar-reasoning-pro"Sonar Reasoning Pro.
pub const MODELS: &[&str] = &[MODEL_SONAR, MODEL_SONAR_PRO, MODEL_SONAR_DEEP_RESEARCH, MODEL_SONAR_REASONING, MODEL_SONAR_REASONING_PRO]Undocumented.
adapters::xai
Own pagexAI.
use utopia_agents::Xai;pub struct Xai(Chat)xAI's OpenAI-compatible chat completions, without structured output.
Errors read {"code": ..., "error": "..."}.
use utopia_agents::{Adapter, Xai};
let adapter = Xai::new("test-api-key");
assert_eq!((adapter.name(), adapter.model()), ("xai", "grok-3-mini"));
assert!(!adapter.is_schema_supported());pub const ENDPOINT: &str = "https://api.x.ai/v1/chat/completions"The chat completions endpoint.
pub const MODEL_GROK_2_IMAGE: &str = "grok-2-image-1212"Grok 2 Image.
pub const MODEL_GROK_3: &str = "grok-3"Grok 3.
pub const MODEL_GROK_3_MINI: &str = "grok-3-mini"Grok 3 Mini (the default).
pub const MODELS: &[&str] = &[MODEL_GROK_3, MODEL_GROK_3_MINI, MODEL_GROK_2_IMAGE]Undocumented.