English | 简体中文
mutil-ai (provider-neutral AI SDK)
A provider-neutral model-invocation SDK for Rust beginners.
Installation
0.5.1: tool_call_content modes no longer drop non-empty assistant content
next to tool_calls — they only shape empty content, as documented. See
CHANGELOG.md.
0.5.0: fixes tool-result pairing, so a correct call id with a differing tool name no longer drops real tool output. See docs/migration-0.5.md.
0.4.1: adds Apache-2.0 as an alternative to MIT, with no API or runtime changes.
0.4.0 security release: this version tightens authentication, tool pairing, stream replay, response budgets and total timeout behavior. See the migration guide and changelog before upgrading from 0.3.x.
- Minimum supported Rust version (MSRV): 1.97.1 (see
rust-versioninCargo.toml) - Optional feature:
blocking(provides the blockingBlockingAdapter/BlockingStream) - License: MIT OR Apache-2.0 (choose either)
Its goal is not to support every advanced feature at once, but to answer one key question first:
Internal agent history can be messy — but before it is sent to a provider, how does it become clean, strictly paired roles and tool calls?
This library does not provide an Agent runtime. It defines its own very small neutral message model, and then lets each provider adapter be responsible only for:
- Invoking the normalization layer;
- Serializing the clean messages into the provider's HTTP request;
- Converting the provider response back into the neutral model.
Session history, tool execution, permission approval, cancellation policy, and loop step limits are decided by downstream projects. examples/minimal_agent.rs in this repository shows how to build a minimal Agent runtime using only the public API; it is not a public capability of the SDK.
Adapters must still follow each provider's HTTP protocol — otherwise the calls simply wouldn't work — but the application layer never has to face those differences directly.
For a summary of protocol surfaces and field differences across major domestic (China) models, see:
For the SDK's long-term contract, current implementation, and handoff checklist, see:
For frozen candidate API semantics intended to help teams evaluate adoption, see:
docs/api-freeze-0.2.mddocs/api-freeze-0.1.md(historical version)
For the implementation handoff of the current version, see:
For a registry of generic extension capabilities required by downstream gateways / agents, see:
For the proposed ChatGPT / Codex authentication architecture and implementation handoff (not yet implemented), see:
docs/chatgpt-codex-auth-design.md(Chinese; client/SDK responsibilities, OAuth, plan inference, and optional app-server integration)
1. Core idea
Internal roles
Applications may internally use these roles:
System / Developer / User / Assistant / Tool / Custom(String)
This lets legacy agents, plugins, and workflows keep their own semantics without having to rewrite their history for some specific provider.
Egress roles
Before anything reaches a provider, only safe roles remain:
System / User / Assistant / Tool
Default downgrade rules:
| Internal role | Egress handling |
|---|---|
System |
Extracted as system instructions |
Developer |
Downgraded to System |
Custom("...") |
Downgraded to User |
User |
User |
Assistant |
Assistant / Gemini's model |
Tool |
The provider's corresponding tool result |
2. Tool-pairing cleanup
What strict providers fear most is "a tool call without a tool result" or "a tool result without a matching tool call".
This library's default rules:
- An assistant
ToolCallwithout an id: automatically assignedcall_1,call_2, etc. - A tool result with an id: paired by that id alone; the tool name is taken from the call it matched.
- A tool result without an id: matched by tool name and given the corresponding id.
- A tool call with no following result: an error result is synthesized automatically, guaranteeing complete pairing.
- Orphan tool results: dropped by default, to avoid polluting upstream. Every drop — and every tool part flattened into plain text on a user/system message — is recorded in the report.
- Anthropic / Gemini: adjacent user/assistant messages are merged, and tool results are placed into the user turn.
You can run the example directly to see the cleanup process:
The output will show:
DowngradedDeveloper
DowngradedCustomRole { role: "reviewer" }
AssignedToolCallId { name: "get_weather", id: "call_1" }
SynthesizedMissingToolResult { call_id: "call_1", name: "get_weather" }
3. Minimal usage: calling a model directly
use ;
async
OPENAI_API_KEY is read from the environment. ModelAdapter here is the stable boundary downstream projects should call directly: pass in a ChatRequest, get back a ChatResponse; use complete_with when you need request-level headers, cancellation, or transforms.
Switching providers requires no changes to business request code:
let model = chat;
// let model = OpenAI::responses("gpt-5.2");
// let model = mutil_ai::Anthropic::messages("claude-sonnet-4-5");
// let model = mutil_ai::Gemini::generate_content("gemini-3-flash");
4. Minimal Agent runtime: an example, not a library capability
The SDK does not export Agent, AgentBuilder, ToolRegistry, or tool_fn. Those types would bake history storage, tool registration, permission models, and termination policy into the library — not a good fit as a stable API for a general-purpose provider core.
The complete minimal runtime lives at:
It depends only on this crate's public types, and implements:
- Keeping the
Vec<Message>history locally; - Putting the system prompt and
ToolSpecs into aChatRequest; - Calling
ModelAdapter::complete_with; - Executing local tools and appending
Message::tool_results; - Looping at most
max_stepstimes.
Run it:
Other projects can copy this file as a starting point and then substitute their own permission approval, cancellation, auditing, and tool dispatch implementations — no need to modify or extend the SDK's public API.
5. Unified chain of thought: message vs. reasoning
Each provider returns thinking content with different field names and containers:
| Protocol | Raw fields |
|---|---|
| OpenAI Chat-compatible API | message.reasoning_content, message.reasoning, message.reasoning_details |
| OpenAI Responses | output item type = "reasoning", which may contain summary, content, encrypted_content |
| Anthropic Messages | content blocks thinking / redacted_thinking, where signature / data must be passed back verbatim |
| Gemini generateContent | part thought: true, thoughtSignature; the signature may also be attached to a functionCall part |
The application layer never needs to inspect these fields. Responses are uniformly turned into:
Text // final message shown to the user; state may carry a Gemini signature
Reasoning
ToolCall // tool call
ToolResult // tool result
ReasoningKind has exactly four variants:
Summary // a summary, e.g. OpenAI Responses summary
Text // human-readable thinking text, e.g. Anthropic thinking / Gemini thought
Encrypted // encrypted reasoning state, unreadable to the user
Redacted // blocks removed by safety policy
state is provider-specific opaque data; it may contain OpenAI reasoning items, Anthropic signature, Gemini thoughtSignature, etc. Applications should not parse or modify it.
Downstream code only needs to match like this:
for part in &response.message.parts
response.text() and message.text_content() never include reasoning, preventing the thinking process from being mistaken for the final answer. To try it:
Request configuration is unified too
Per-provider toggles are likewise mapped by the adapter:
use ;
let request = user
.reasoning;
Mapping rules:
- OpenAI Chat:
effort->reasoning_effort - OpenAI Responses:
effort/summary/include_encrypted->reasoningandinclude - Anthropic:
mode/budget_tokens/include_text->thinking - Gemini:
effort/budget_tokens/include_text->generationConfig.thinkingConfig
Unsupported target fields are ignored — the library never guesses an approximate field and stuffs the value in there.
Common request controls also have a neutral representation:
use ;
let request = user
.tools
.tool_choice
.response_format
.stop
.seed;
Each protocol maps only the fields it supports; for example, Anthropic does not accept the neutral response_format and will return Unsupported rather than silently ignoring it.
Replay boundaries
- Reasoning
statefrom the same protocol is replayed verbatim. - Anthropic's
thinking/redacted_thinkingblocks are placed back into the assistant content in their original order. - OpenAI Responses reasoning items are placed back into
inputas the original objects. - Gemini's
thoughtSignatureis preserved on the corresponding reasoning part, tool call, or visible text part. - Opaque state across protocols is dropped by default in the normalization layer — Claude/Gemini signatures are never sent to OpenAI.
- Reasoning inside non-assistant messages is dropped by default and recorded in
NormalizeReport; it is never silently promoted into user text.
This way the egress layer still only knows one simple set of content types, and provider special cases are confined to adapters.
Reference links:
- OpenAI Reasoning: https://developers.openai.com/api/docs/guides/reasoning
- Anthropic Extended Thinking: https://platform.claude.com/docs/en/build-with-claude/extended-thinking
- Gemini Thinking: https://ai.google.dev/gemini-api/docs/thinking
- Gemini Thought Signatures: https://ai.google.dev/gemini-api/docs/thought-signatures
- OpenRouter Reasoning Tokens: https://openrouter.ai/docs/use-cases/reasoning-tokens
6. Unified streaming
All four built-in adapters implement:
async ;
Downstream code only sees the unified StreamEvent:
Usage example:
use ;
let model = chat;
let request = user;
let mut stream = model.stream.await?;
while let Some = next_event.await
Key problems already handled:
- OpenAI Chat:
delta.content,reasoning_content,reasoning_details - OpenAI Responses: text / reasoning summary / reasoning text / function arguments events
- Anthropic:
content_block_delta,thinking_delta,signature_delta,input_json_delta - Gemini:
:streamGenerateContent?alt=sse, thought, text, functionCall, thoughtSignature - Tool arguments are accumulated by index and parsed into JSON in
Done.response - Reasoning text and the final signature/encrypted state remain intact in
Done.response - Usage is sent as its own event and also kept in the final response
Start.metadataandDone.response.metadatainclude status, request id, and response headers- The SSE
retry:field is mapped toStreamEvent::Retry
Current boundaries:
- HTTP errors before the stream starts receiving are retried according to
RetryPolicy. - Transport disconnections after the stream starts can be handled with explicitly enabled reconnect.
- Reconnect requires seeing an SSE
id, sendsLast-Event-ID, and reuses the same mapper. - Replay suppression is opt-in with
.deduplicate_replay(true)and only applies to a reconnected replay suffix. Ordinary connections preserve repeated events and inherited SSE IDs. - Only Chat/Gemini treat EOF as a normal end; Responses/Anthropic treat an EOF without a terminal event as a recoverable disconnect.
collect_streamlets you skip incremental rendering and simply collect the finalChatResponse.
Enabling disconnect reconnect:
use Duration;
use ;
let options = new.stream_reconnect;
let mut stream = model.stream_with.await?;
On reconnect the following is sent:
Last-Event-ID: <last-seen-id>
Session, idempotency key, and the original request body remain unchanged.
Runnable example:
7. How retry headers are recognized
Retry-After is an HTTP response header, not a body field. It commonly appears with:
429 Too Many Requests503 Service Unavailable
It has two formats:
Retry-After: 120
meaning wait 120 seconds.
Retry-After: Wed, 21 Oct 2026 07:28:00 GMT
meaning wait until this HTTP date. If the date is already in the past, the wait time is treated as 0.
This library will:
- Check the response's
retry-afterheader; - First try to parse it as a number of seconds;
- Fall back to parsing it as an HTTP date;
- Store it in
Error::Api.retry_after; - Expose it to retry logic via
error.retry_after()anderror.is_retryable().
use Duration;
match model.complete.await
Errors carry a stable classification, so there is no need to match on error strings:
use ErrorKind;
match model.complete.await
Error also provides:
kind(): the stableErrorKind;status(): the HTTP status;provider(): the provider name;request_id(): the request id from the response, if available;retry_after()/retry_source();is_retryable();body_bytes(): the byte length of the provider error body;provider_error(): a safe structured error summary;raw_body(): explicitly read the provider's raw error body.
provider_error() understands common OpenAI/Anthropic/Gemini structures as well as compatible gateways, and returns a length- and character-whitelist-sanitized code, error_type, status, message byte count, and details count; it does not return the provider message verbatim.
By default, Error::Api's Display and Debug do not output the provider body, preventing eprintln! or logging frameworks from accidentally recording echoed prompts, account information, or tool content. Only an explicit call to raw_body() or direct field access retrieves the raw text.
RetryPolicy design
Retry logic is layered in three tiers:
Retry-After / status code
↓
RetryPolicy::delay_for()
↓
retry_async / send_json_retry
↓
adapter
The adapter never decides how long to sleep itself; it is only responsible for rebuilding the HTTP request.
use ;
use Duration;
let model = responses.retry_policy;
Rules:
- Retry only when
error.is_retryable()is true. - If
Retry-Afteris present: respect the server-provided time first. - If
Retry-Afterexceedsmax_retry_after: stop, to avoid waiting forever. - If there is no
Retry-After: exponential backoff with jitter. max_attemptsincludes the first request.- By default
require_idempotency_key = true: without anIdempotency-Key, the request is sent once and POSTs are not replayed automatically.
Explicitly accepting retries without an idempotency key:
let policy = default
.max_attempts
.require_idempotency_key;
Only turn off this protection when you know for certain the request can be safely replayed.
Header priority
The parsing order is fixed:
1. retry-after-ms
2. retry-after
3. provider-specific reset headers
retry-after-ms is not a standard header, but the official OpenAI, Anthropic, and Google SDKs all support it, and it has better precision than whole seconds.
OpenAI
In the official OpenAPI spec, 429 and 503 responses return:
Retry-After: 3
The official Python SDK also recognizes, with priority:
retry-after-ms: 1500
As a fallback, this library also supports:
x-ratelimit-reset-requests: 6m0s
x-ratelimit-reset-tokens: 1h
Supporting ns / us / µs / ms / s / m / h as well as combined forms, e.g. 1h30m.
Anthropic
The official SDK likewise prefers retry-after-ms, then retry-after.
Anthropic's reset headers are RFC3339 UTC timestamps:
anthropic-ratelimit-requests-reset: 2026-02-25T20:02:32Z
anthropic-ratelimit-tokens-reset: 2026-02-25T20:02:36Z
anthropic-ratelimit-input-tokens-reset: 2026-02-25T20:02:37Z
anthropic-ratelimit-output-tokens-reset: 2026-02-25T20:02:36Z
Google Gemini
The official python-genai SDK supports:
retry-after-ms: 1
Google API error bodies may also contain RetryInfo.retryDelay, but that is not a header, so the current version does not mix it into the header-parsing layer.
Reference links:
- OpenAI Rate Limits: https://developers.openai.com/api/docs/guides/rate-limits
- Anthropic Rate Limits: https://platform.claude.com/docs/en/api/rate-limits
- Gemini Rate Limits: https://ai.google.dev/gemini-api/docs/rate-limits
8. Hand-written SSE parser
src/sse.rs is an incremental, zero-I/O SSE parser:
let mut parser = new;
for chunk in response.bytes_stream
It does not depend on sse-stream, tokio-util, or http-body; it only handles byte state.
Supported:
- Arbitrary chunk splits
\n,\r\n, and lone\r- UTF-8 BOM
- Comments and unknown fields
- Multi-line
data event,id,retryidinheritance across eventseventreset after dispatch- Line/event size limits
- Incomplete events discarded at EOF
UTF-8 handling follows WHATWG EventSource by default: invalid bytes are replaced with U+FFFD. For sse-stream-style strict errors, use:
let parser = strict;
Correctness tests cover:
- Splitting at every byte boundary
- CRLF across chunks
- BOM across chunks
- Multi-line data
- ID inheritance
- Event reset
- Invalid retry values and overflow
- NUL IDs
- Colonless data
- UTF-8 replace / strict
- CJK split in the middle of a codepoint
- Emoji split in the middle of a codepoint
- CJK event/id/data
- Line limits counted in UTF-8 bytes
- BOM followed by CJK
- Incomplete events at EOF
Comparison tests against sse-stream 0.3.0:
The first test simulates 200,000 tokens — a 10,000 tok/s stream sustained for 20 seconds — measured at 1 / 10 / 100 events per chunk.
The second test dynamically selects 1 / 4 / 8 / 12 concurrent clients based on the machine's logical CPU count; each client parses 300,000 tokens, measuring:
- Worker CPU time
- CPU time per token
- CPU coefficient of variation across rounds
- CPU coefficient of variation across clients
- CPU headroom relative to 10,000 tok/s
Results on the current machine:
1-8 clients:
手写 parser 的每 token CPU 更低,通常低 15%-35%
两种实现的轮次波动都很小
12/12 logical CPUs, 1 event/chunk:
手写 parser 仍然更低
12/12 logical CPUs, 10 events/chunk:
sse-stream 的每 token CPU 略低,客户端间波动也更小
所有场景:
两种 parser 相对 10,000 tok/s 都有约 85x-230x CPU 余量
This shows that 10,000 tok/s is nowhere near the SSE parser's saturation point. What actually drives CPU fluctuation is mainly JSON, networking, the model service, logging, and upper-level agent scheduling — not SSE byte parsing. Under concurrent saturation, the memory allocator, SMT, and the scheduler begin to matter more than the parser itself.
Isolated comparison against qaqh-gate's SseDecoder
In a separate worktree, qaqh's data-only decoder was compared directly against this library's general-purpose parser:
release, 500,000 events, 5 samples
After optimization:
ASCII:
qaqh 约 83-95 ns/event
mutil-ai 约 121-125 ns/event
差距约 1.3x-1.47x
CJK + emoji:
qaqh 约 107-109 ns/event
mutil-ai 约 144-154 ns/event
差距约 1.34x-1.42x
Multiple clients:
1-8 clients:
每事件 CPU 差距约 1.14x-1.47x
12 logical CPUs:
差距扩大,约 2.0x-2.4x
主要来自分配器、SMT 和调度竞争
qaqh's decoder only handles data:, does not preserve event/id/retry, and does not enforce a strict UTF-8 policy, so it being faster is the expected outcome; this library keeps full SSE semantics and the state needed for reconnect.
10,000-session stress test
Added:
Test model:
- 10,000 parser states alive simultaneously;
- 12 workers rotating through sessions;
- Each session parsed independently;
- Total event counts verified — any loss fails the test;
- The regular smoke test runs on every commit;
- The heavy version with 100 events/session is marked ignored.
Current release results on this machine:
qaqh: 约 46M-60M events/s
mutil-ai: 约 17M-18M events/s
Based on a typical website workload of 10,000 concurrent sessions with an average of 10-100 events/s per session:
总事件率约 100k-1M events/s
mutil-ai 仍有约 17x-170x 的解析余量
So the ten-thousand-session target is not bottlenecked by the SSE parser; the real constraints are:
- Per-session memory footprint;
- Async task count and scheduling;
- Network connections/TLS;
- JSON and business state machines;
- Logging and audit pipelines.
9. Headers and User-Agent
The SDK provides a default UA, but clients may override it:
let transport = new
.user_agent?
.header?
.client_info;
let model = responses.transport;
Request-level headers:
let options = new
.header?
.user_agent?
.context;
Business fields like x-sessionid and x-tenant-id are not hard-coded into adapters; clients pass them through.
Dynamic auth or session headers go through HeaderInjector:
use Arc;
use async_trait;
use ;
;
let transport = new
.header_injector;
Header priority:
SDK 默认 UA
↓
ClientConfig / TransportConfig
↓
RequestOptions
↓
HeaderInjector
Authorization, Content-Type, Content-Length, Host, and Accept are protected headers by default and cannot be silently overridden by ordinary configuration layers. HeaderInjector is part of the trusted transport configuration and may set Authorization, making it suitable for OAuth/token refresh scenarios.
For idempotent requests, pass:
let options = new.idempotency_key;
The SDK sends Idempotency-Key: request-123, and retries of the same logical request reuse the same key.
Custom headers must be ASCII by default. Non-ASCII values such as CJK must be encoded by the caller — e.g. base64 or percent encoding; otherwise NonAsciiHeaderValue is returned.
HeaderInjector is re-executed before every HTTP attempt. Automatic retries can refresh tokens or transient headers, but session, idempotency key, static body, and static headers remain stable for the same logical request. Automatic replay is still not performed once stream deltas have been produced.
Auditing and data points (no context retention)
Auditing is off by default; when enabled, it records only structured transport events — never prompts, messages, reasoning, tool arguments/results, request bodies, or response bodies:
use Arc;
use ;
;
let transport = new
.audit_sink
.audit_config;
Auditable data points include:
RequestStartedAttemptStartedResponseHeadersAttemptFinishedFirstTokenNormalizationRetryScheduledStreamReconnectScheduledRequestFinished(Success/Failure/Cancelled)
Each event may include:
- provider, protocol, model;
- attempt number;
- status, duration, outcome;
- time to response headers and streaming TTFT;
- request body byte count and cumulative decoded response body byte count;
ErrorKindand whether it is retryable;- usage;
- provider request id;
- aggregate counts of normalization fix types;
- profile id / model profile hit status / capability snapshot, only when explicitly enabled.
ResponseHeaders.elapsed and RequestFinished.timing.time_to_headers are measured from the start of the logical request. They include the total time for DNS, connection, TLS, request sending, and server processing until the response headers arrive; reqwest does not expose the individual timestamps of these stages to this SDK, so finer-grained connect/TLS splits are not fabricated. time_to_first_token is produced only when a streaming response receives its first text, reasoning, or tool-call delta.
Normalization contains only counts per fix type, e.g. developer downgrades and tool call/result pairing repairs. It never records custom role names, tool names, call ids, or message content.
RequestFinished.bytes.request_body is the size of the serialized body of a single attempt; bytes.response_body is the cumulative decoded byte count received across retries/reconnects for this logical request, including provider error bodies but excluding body content.
When a stream is dropped by the consumer before a terminal event arrives, RequestFinished { outcome: Cancelled } is emitted. This can be disabled with record_cancellation(false), or client-initiated cancellations can be distinguished from provider failures in your metrics.
Not included by default:
- session id;
- SDK request id;
- profile id and capability snapshot;
- prompt / message / reasoning / tool content;
- request/response bodies.
Correlation IDs must be explicitly opted into:
let config = enabled
.include_provider_request_id
.include_sdk_request_id
.include_session_id
.include_usage
.include_profile
.record_timing
.record_normalization;
The session id is off by default because it may contain tenant or user context. Custom profile ids may also encode tenant information, so they are excluded from audits by default.
For production, a non-blocking bounded queue is recommended:
use ;
let = bounded_audit_channel;
let transport = new
.audit_sink
.audit_config;
// receiver 应交给后台线程/任务处理。
let snapshot = stats.snapshot;
println!;
When the queue is full, events are dropped and counted immediately — model requests are never blocked. sample_every(N) samples per whole logical request, avoiding samples that capture attempts but miss the final result.
10. Explicit endpoints and extension fields
A single vendor may simultaneously offer Chat Completions, Responses, and Anthropic protocols. The base URL alone cannot determine behavior, so generic adapters require an explicit EndpointSpec:
use ;
let profile = qwen_compatible;
let endpoint = new
.profile;
let model = new
.api_key_from_env;
OpenAICompatible remains as a compatibility alias for EndpointAdapter; new code should prefer EndpointAdapter, since it dispatches to all of:
OpenAiChat
OpenAiResponses
AnthropicMessages
GeminiGenerateContent
The protocol must still be chosen explicitly by the caller — never guessed from the URL. Gemini's normal and streaming paths are also described separately by EndpointSpec.
Built-in presets describe behavior only and are not bound to any URL:
deepseek_compatible;
qwen_compatible;
kimi_compatible;
glm_compatible;
doubao_compatible;
You can also look up presets by an explicit ProfileId — still no URL guessing:
use ;
let endpoint = openai_chat
.profile_selector;
An unknown id returns Unsupported; it never falls back to URL guessing.
For example, the Qwen preset converts the neutral configuration into:
ReasoningMode::Disabled -> enable_thinking = false
ReasoningConfig::budget_tokens -> thinking_budget
The DeepSeek preset converts thinking.type and uses the effort mapping its documentation requires:
minimal -> low
medium -> high
xhigh -> high
Model-level differences are overridden with ModelProfile. The SDK already provides two common Kimi presets:
use ;
let model = new
.api_key_from_env
.model_profile;
let model = new
.api_key_from_env
.model_profile;
kimi_k2_6() generates:
Capabilities are checked before the request is sent:
let mut profile = qwen_compatible;
profile.capabilities.multimodal = false;
At that point, a request containing images returns Unsupported instead of first sending a request that is guaranteed to fail.
Provider extension fields for a single request:
let request = user
.extra_body
.extra_body;
let options = new
.header?
.extra_query;
The merge rule is: profile defaults are written first, then request-level extra_body, so same-named extension fields are overridden by the single request. Canonical fields such as model, messages, input, and stream cannot be overridden; conflicts return ReservedExtraBodyField before the request is sent, rather than silently producing a broken request.
EndpointAdapter dispatches to Chat, Responses, Anthropic, or Gemini based on EndpointSpec.protocol; the normal path and Gemini's streaming path are both configured explicitly — never inferred from the URL.
11. Code structure
src/
types.rs 中立 message / reasoning / provider state
normalize.rs 内部 role -> 出口 role,工具配对和跨协议清洗
profile.rs EndpointSpec / ProviderProfile / ModelProfile
adapter/
openai_chat.rs OpenAI Chat Completions
endpoint.rs 显式 EndpointSpec 的四协议 dispatch
openai_responses.rs OpenAI Responses
anthropic.rs Anthropic Messages
gemini.rs Gemini generateContent
retry.rs Retry-After / reset header / backoff
sse.rs 手写增量 SSE parser
stream.rs 统一 StreamEvent 和流式事件组装
headers.rs UA / 请求头 / query / 注入接口
examples/
hello.rs 直接调用 ModelAdapter 的最小示例
minimal_agent.rs 只使用公开 API 的 Agent runtime 示例
Key point: role conversion, tool repairs, and cross-provider reasoning cleanup happen exactly once, in normalize.rs — adapters do not each maintain their own patch set.
12. What the current version deliberately does not do
This is v0.5.0; the current priority is getting roles, tool pairing, retry, SSE, reasoning, unified streaming, cancellation, and the generic provider extension boundary clearly defined. For now, the following are out of scope:
- WebSocket / Realtime
- OpenAI Responses'
previous_response_id/store - Anthropic
cache_control - Gemini Interactions API
- embedding / rerank / speech
- Automatically translating reasoning between different providers; the current choice is to safely drop it rather than guess
All of these can be added later — but they should be added in clearly defined places, not by stuffing provider special cases into the downstream runtime or the example Agent loop.
License
This project's code and documentation are dual-licensed under the
MIT License or Apache License, Version 2.0,
at your option (MIT OR Apache-2.0, not a requirement to comply with both).
Either license permits commercial use, modification, and distribution,
including use in closed-source products, subject to the chosen license's
conditions. Keep the required license and attribution notices when distributing;
Apache-2.0 also requires notices for modified files. Third-party dependencies
retain their own licenses.
mutil-ai is an independent, unofficial SDK. Its license does not grant access to model-provider services or imply authorization, sponsorship, or endorsement by OpenAI, Anthropic, Google, or other providers. API use remains subject to the provider's applicable terms, usage policies, and account/access requirements; SDK licensing does not override restrictions on service resale, competing products, or bypassing access controls. See the applicable OpenAI, Anthropic, and Gemini API terms.
Contributors
- QAQTam — project maintainer.
- OpenAI Codex — AI-assisted contributions to the v0.4.0 security audit, hardening, dependency review, and release preparation.