providers

Anthropic + OpenAI today.

Same Provider trait for both. SSE streaming. Tool use. Configurable base URLs for Azure and proxies. Google Gemini and Ollama are tracked on the roadmap; both will reuse the existing trait.

shipped

Streaming, tool use, drop-in today

  • AnthropicProvider Anthropic Messages API

    Claude 3.5 Sonnet · Haiku · Opus

    Full async client. SSE streaming, tool use, content blocks, custom base URLs.

  • OpenAIProvider OpenAI Chat Completions

    GPT-4o · GPT-4 · GPT-3.5

    Azure-compatible base URLs, org-id headers, function calling, SSE streaming.

planned

On the roadmap

  • GoogleProvider Gemini API

    Gemini 2.5 Pro · Flash

    Roadmap item — see docs/ROADMAP.md. Will reuse the existing Provider trait.

  • OllamaProvider localhost:11434

    Any Ollama-served model

    Local-only deployments. Shares the streaming abstraction.

The Provider trait

Every provider implements the same async trait. Adding a new one is a single-crate addition, not an architecture change.

rust
#[async_trait]
pub trait Provider: Send + Sync {
    async fn complete(&self, req: CompletionRequest) -> Result<CompletionResponse>;
    async fn complete_stream(&self, req: CompletionRequest) -> Result<CompletionStream>;
    fn name(&self) -> &str;
}

Anthropic

Full Anthropic Messages API client. Supports content blocks, tool use, system prompts, and vision.

rust
use openclaw_providers::{AnthropicProvider, Provider, CompletionRequest, Message, Role, ContentBlock};
use openclaw_core::secrets::ApiKey;

let provider = AnthropicProvider::new(ApiKey::new("sk-ant-...".into()));

let response = provider.complete(CompletionRequest {
    model: "claude-3-5-sonnet-20241022".to_string(),
    messages: vec![Message {
        role: Role::User,
        content: vec![ContentBlock::Text { text: "Hello!".to_string() }],
    }],
    max_tokens: Some(1024),
    ..Default::default()
}).await?;

OpenAI

Full Chat Completions client with function calling, Azure-compatible base URL, organisation ID headers.

rust
use openclaw_providers::{OpenAIProvider, Provider};

let provider = OpenAIProvider::new(ApiKey::new("sk-...".into()))
    .with_base_url("https://my-azure-endpoint.openai.azure.com/")
    .with_organization("org-...");

let response = provider.complete(request).await?;

Streaming

Both providers expose SSE streaming through the same complete_stream method.

rust
let mut stream = provider.complete_stream(request).await?;
while let Some(chunk) = stream.next().await {
    let delta = chunk?.delta;
    print!("{}", delta);
}

Roadmap providers

Google Gemini — Gemini 2.5 Pro / Flash via the Gemini API. Same Provider trait, same streaming abstraction. Track in docs/ROADMAP.md.

Ollama — for fully-local deployments. Pulls models from localhost:11434. Useful for on-host inference with no external API.

Per-agent provider routing

Agents can be configured with different providers. A "fast" agent uses Haiku; a "deep" agent uses Opus; a "cheap" agent uses GPT-3.5. The runtime dispatches per AgentSpec.

rust
let fast_agent = AgentSpec::new("fast")
    .with_provider(AnthropicProvider::new(key.clone()))
    .with_model("claude-3-5-haiku-20241022");

let deep_agent = AgentSpec::new("deep")
    .with_provider(AnthropicProvider::new(key.clone()))
    .with_model("claude-3-5-sonnet-20241022");
next

Wire it up to a channel.

Once you have providers configured, route inbound traffic from Telegram — or use the gateway directly over JSON-RPC.