Expand description
One small Rust API for OpenAI, Anthropic, OpenRouter, Groq, DeepSeek, Gemini, xAI, Mistral, Ollama, and any OpenAI-compatible endpoint.
use modelbridge::{Client, Request};
let client = Client::default_for("anthropic")?;
let answer = client.complete(&Request::new("Be brief").user("Why is the sky blue?"))?;
println!("{} ({} tokens)", answer.text, answer.usage.total());Everything is synchronous and runtime-free. Provider::stream blocks and
pushes Chunks down an mpsc channel, which is what a TUI or GUI wants:
run it on a worker thread and drain the channel each frame.
PROVIDERSandMODELSknow the endpoint, credential variable, wire format, and price of the providers people actually use, without ever restricting the model id you pass.agentruns the call-tools-until-answered loop, feeding results back in each provider’s native format.oauthis the whole browser sign-in flow for the ChatGPT and Claude subscription routes, including refresh and storage. On by default; turn it off withdefault-features = falseand three dependencies go with it.
Modules§
- agent
- The loop: ask, run whatever tools the model asked for, hand the results back, repeat until it answers.
- oauth
- Browser sign-in for the two providers people reach with a subscription rather than a key.
Structs§
- Client
- A configured route to one provider.
- Client
Builder - Message
- One turn of the conversation.
- Model
Spec - Provider
Spec - Request
- One request, whatever the provider underneath.
- Response
- A finished reply.
- Retry
- How many times a transient failure is worth repeating, and how long to wait
first. A server that sends
Retry-Afteroverrides the delay. - Tool
Call - A tool invocation the model asked for.
- Tool
Result - What a tool produced, on its way back to the model.
- Tool
Schema - A function the model may call, described with JSON Schema.
- Usage
- What a client has spent, in tokens and in millionths of a dollar.
Enums§
Constants§
Traits§
- OAuth
Token Provider - Supplies OAuth access tokens while the host application owns login, persistence, expiry, scopes, and refresh-token security.
- Provider
- Anything that can answer a
Request.
Functions§
- collect_
text complete, keeping only the text.- complete
- Consume a streaming provider into one
Response. - extract_
json - The first well-formed JSON object in a string, tolerating code fences and whatever prose a model wrapped around it.
- model
- models_
for - provider