opi-ai
Provider abstraction with streaming support for opi — a Rust port of pi.
Status (v0.2.0)
Phase 1 ships a complete streaming pipeline for Anthropic Messages. The
Provider trait, registry, message types, and 12-variant
AssistantStreamEvent model are designed to support multiple providers, but
only Anthropic is wired up in this release. OpenAI, Google, Mistral, Bedrock,
and Azure providers are reserved on the ProviderKind enum and will follow in
later phases.
What's in the box
Providertrait —stream(Request) -> EventStreamwith cancellation viatokio_util::sync::CancellationToken.anthropic— Anthropic Messages SSE provider with a hand-written SSE parser that surfaces malformed events (instead of silently dropping them) and handles CRLF line endings.registry::ProviderRegistry— resolvesprovider:modelspecs to aProvider+ModelInfo, plus capability queries (context_window,max_output_tokens,supports_streaming,supports_thinking).message—Message,AssistantMessage,UserMessage,ToolResultMessage,ToolDef,ToolCall, content variants.stream::AssistantStreamEvent— 12 variants (Start,Text*,Thinking*,ToolCall*,Done,Error); token usage is carried onDoneviaAssistantMessage, not as a separate stream event.test_support::MockProvider— builder-style mock for integration tests (used byopi-agentandopi-coding-agent).
Usage
use AnthropicProvider;
use ;
use ;
use CancellationToken;
use StreamExt;
# async
Modules
| Module | Purpose |
|---|---|
provider |
Provider trait, Request, EventStream, ModelInfo, ProviderError, ProviderKind |
anthropic |
Anthropic SSE provider, SSE parser, event mapper |
registry |
provider:model spec resolution and capability lookup |
message |
LLM message types and tool-call types |
stream |
AssistantStreamEvent, StopReason, Usage |
model |
Model re-export |
config |
Config and Error (shared with downstream crates) |
test_support |
Mock provider for tests (#[doc(hidden)]) |
License
MIT — see workspace LICENSE.