Rust

adapters

Module

The provider adapters.

Contents

11 submodules.

adapters::anthropic

Own page

Anthropic.

use utopia_agents::Anthropic;
Rust
pub struct Anthropic

Anthropic'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.

Rust
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"));
Rust
pub const API_VERSION: &str = "2023-06-01"

The API version requests ask for (anthropic-version).

Rust
pub const ENDPOINT: &str = "https://api.anthropic.com/v1/messages"

The Messages API endpoint.

Rust
pub const MODEL_CLAUDE_3_5_HAIKU: &str = "claude-3-5-haiku-latest"

Claude 3.5 Haiku.

Rust
pub const MODEL_CLAUDE_3_5_SONNET: &str = "claude-3-5-sonnet-latest"

Claude 3.5 Sonnet.

Rust
pub const MODEL_CLAUDE_3_7_SONNET: &str = "claude-3-7-sonnet-latest"

Claude 3.7 Sonnet.

Rust
pub const MODEL_CLAUDE_3_HAIKU: &str = "claude-3-haiku-20240307"

Claude 3 Haiku (the default).

Rust
pub const MODEL_CLAUDE_3_OPUS: &str = "claude-3-opus-latest"

Claude 3 Opus.

Rust
pub const MODEL_CLAUDE_4_OPUS: &str = "claude-opus-4-0"

Claude 4 Opus.

Rust
pub const MODEL_CLAUDE_4_SONNET: &str = "claude-sonnet-4-0"

Claude 4 Sonnet.

Rust
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 page

Appwrite's embedding service.

use utopia_agents::Appwrite;
Rust
pub struct Appwrite

Embeddings from Appwrite's embedding service (no API key), several texts per request. It does not chat: Adapter::send fails.

Rust
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);
Also implements Default.
use utopia_agents::adapters::appwrite::dimension;
Rust
pub fn dimension(model: &str) -> Option<i64>

The size of a model's embeddings.

Rust
pub const ENDPOINT: &str = "http://appwrite-embedding:11434/embed"

The embed endpoint of the embedding service.

Rust
pub const MODEL_ALL_MINILM: &str = "all-minilm"

all-MiniLM-L6-v2: small and fast.

Rust
pub const MODEL_BGE_SMALL: &str = "bge-small"

BGE Small EN v1.5: small, English.

Rust
pub const MODEL_EMBEDDING_GEMMA: &str = "embedding-gemma"

EmbeddingGemma 300M.

Rust
pub const MODEL_NOMIC_EMBED_TEXT: &str = "nomic-embed-text"

Nomic Embed Text v1.5: general purpose (the default).

Rust
pub const MODELS: &[&str] = &[MODEL_NOMIC_EMBED_TEXT, MODEL_EMBEDDING_GEMMA, MODEL_ALL_MINILM, MODEL_BGE_SMALL]

Every model.

adapters::chat

Own page

The OpenAI chat completions protocol, which OpenAI, OpenRouter, Perplexity and xAI speak, each with its own differences (Dialect).

adapters::deepseek

Own page

Deepseek.

use utopia_agents::Deepseek;
Rust
pub struct Deepseek

Deepseek'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).

Rust
use utopia_agents::{Adapter, Deepseek};

let adapter = Deepseek::new("test-api-key");
assert_eq!((adapter.name(), adapter.model()), ("deepseek", "deepseek-chat"));
Rust
pub const ENDPOINT: &str = "https://api.deepseek.com/chat/completions"

The chat completions endpoint.

Rust
pub const MODEL_DEEPSEEK_CHAT: &str = "deepseek-chat"

Deepseek Chat (the default).

Rust
pub const MODEL_DEEPSEEK_CODER: &str = "deepseek-coder"

Deepseek Coder.

Rust
pub const MODELS: &[&str] = &[MODEL_DEEPSEEK_CHAT, MODEL_DEEPSEEK_CODER]

Undocumented.

adapters::gemini

Own page

Google Gemini.

use utopia_agents::Gemini;
Rust
pub struct Gemini

Google'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.

Rust
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;
Rust
pub fn endpoint(model: &str, api_key: &str) -> String

The streaming endpoint of a model, with the API key in the query.

Rust
pub const MODEL_GEMINI_1_5_PRO: &str = "gemini-1.5-pro"

Gemini 1.5 Pro.

Rust
pub const MODEL_GEMINI_2_0_FLASH: &str = "gemini-2.0-flash"

Gemini 2.0 Flash (the default).

Rust
pub const MODEL_GEMINI_2_0_FLASH_LITE: &str = "gemini-2.0-flash-lite"

Gemini 2.0 Flash Lite.

Rust
pub const MODEL_GEMINI_2_5_FLASH_PREVIEW: &str = "gemini-2.5-flash-preview-04-17"

Gemini 2.5 Flash Preview.

Rust
pub const MODEL_GEMINI_2_5_PRO_PREVIEW: &str = "gemini-2.5-pro-preview-03-25"

Gemini 2.5 Pro Preview.

Rust
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 page

Ollama (embeddings).

use utopia_agents::Ollama;
Rust
pub struct Ollama

Embeddings from a local Ollama service (no API key). It does not chat: Adapter::send fails.

Rust
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());
Also implements Default.
use utopia_agents::adapters::ollama::dimension;
Rust
pub fn dimension(model: &str) -> Option<i64>

The size of a model's embeddings.

Rust
pub const ENDPOINT: &str = "http://ollama:11434/api/embed"

The embed endpoint of the local Ollama service.

Rust
pub const MODEL_EMBEDDING_GEMMA: &str = "embeddinggemma"

EmbeddingGemma (the default and only model).

Rust
pub const MODELS: &[&str] = &[MODEL_EMBEDDING_GEMMA]

Every model.

adapters::openai

Own page

OpenAI.

use utopia_agents::OpenAi;
Rust
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.

Rust
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");
Rust
pub const ENDPOINT: &str = "https://api.openai.com/v1/chat/completions"

The chat completions endpoint.

Rust
pub const MODEL_GPT_4_1: &str = "gpt-4.1"

GPT-4.1.

Rust
pub const MODEL_GPT_4_5_PREVIEW: &str = "gpt-4.5-preview"

GPT-4.5 Preview.

Rust
pub const MODEL_GPT_4O: &str = "gpt-4o"

GPT-4o: multimodal, text and images.

Rust
pub const MODEL_GPT_5_NANO: &str = "gpt-5-nano"

GPT-5 Nano: a small GPT-5 for low latency and cost-sensitive work.

Rust
pub const MODEL_O3: &str = "o3"

o3.

Rust
pub const MODEL_O3_MINI: &str = "o3-mini"

o3-mini (the default).

Rust
pub const MODEL_O4_MINI: &str = "o4-mini"

o4-mini.

Rust
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 page

OpenRouter.

use utopia_agents::OpenRouter;
Rust
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.

Rust
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"));
Rust
pub const ENDPOINT: &str = "https://openrouter.ai/api/v1/chat/completions"

The chat completions endpoint.

adapters::openrouter::models

Own page

OpenRouter'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 page

Perplexity.

use utopia_agents::Perplexity;
Rust
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.

Rust
use utopia_agents::{Adapter, Perplexity};

let adapter = Perplexity::new("test-api-key");
assert_eq!((adapter.name(), adapter.model()), ("perplexity", "sonar"));
Rust
pub const ENDPOINT: &str = "https://api.perplexity.ai/chat/completions"

The chat completions endpoint.

Rust
pub const MODEL_SONAR: &str = "sonar"

Sonar: lightweight search (the default).

Rust
pub const MODEL_SONAR_DEEP_RESEARCH: &str = "sonar-deep-research"

Sonar Deep Research.

Rust
pub const MODEL_SONAR_PRO: &str = "sonar-pro"

Sonar Pro.

Rust
pub const MODEL_SONAR_REASONING: &str = "sonar-reasoning"

Sonar Reasoning.

Rust
pub const MODEL_SONAR_REASONING_PRO: &str = "sonar-reasoning-pro"

Sonar Reasoning Pro.

Rust
pub const MODELS: &[&str] = &[MODEL_SONAR, MODEL_SONAR_PRO, MODEL_SONAR_DEEP_RESEARCH, MODEL_SONAR_REASONING, MODEL_SONAR_REASONING_PRO]

Undocumented.

adapters::xai

Own page

xAI.

use utopia_agents::Xai;
Rust
pub struct Xai(Chat)

xAI's OpenAI-compatible chat completions, without structured output. Errors read {"code": ..., "error": "..."}.

Rust
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());
Rust
pub const ENDPOINT: &str = "https://api.x.ai/v1/chat/completions"

The chat completions endpoint.

Rust
pub const MODEL_GROK_2_IMAGE: &str = "grok-2-image-1212"

Grok 2 Image.

Rust
pub const MODEL_GROK_3: &str = "grok-3"

Grok 3.

Rust
pub const MODEL_GROK_3_MINI: &str = "grok-3-mini"

Grok 3 Mini (the default).

Rust
pub const MODELS: &[&str] = &[MODEL_GROK_3, MODEL_GROK_3_MINI, MODEL_GROK_2_IMAGE]

Undocumented.