Expand description
§openai-client-rs
A Rust client for the OpenAI API — chat completions, embeddings, images, audio, files, and streaming SSE. Compatible with OpenAI and any OpenAI-compatible provider (DeepSeek, Kimi, MiniMax, Ollama, etc).
§Features
- Sync (default) — lightweight
ureq - Async — optional
reqwest+tokio(features = ["async"]) - Chat Completions — full API with streaming SSE
- Models / Embeddings / Images / Audio / Files
- Tool calling — function calling with fragmented argument accumulation
- Reasoning — thinking extraction from
reasoning_content/reasoning/thinkingfields and inline<think>...</think>tags (DeepSeek / Kimi / Qwen and other providers) - Vision — image URL and base64 inputs
- Auto-retry — exponential backoff with jitter and
Retry-Aftersupport - Token counting — approximate message token estimation
- Multi-provider — OpenAI, DeepSeek, Kimi, MiniMax, Ollama
§Quick start
use openai_client_rs::{OpenAiClient, ChatMessage};
let client = OpenAiClient::new("sk-xxx", "gpt-4o");
let resp = client.chat_create(
&[ChatMessage::user("Hello!")],
None,
).unwrap();
println!("{}", resp.text);Re-exports§
pub use audio::SpeechRequest;pub use audio::TranscriptionRequest;pub use audio::TranscriptionResponse;pub use error::ApiError;pub use error::OpenAiError;pub use error::Result;pub use files::FileList;pub use files::FileObject;pub use images::ImageData;pub use images::ImageRequest;pub use images::ImageResponse;pub use models::ModelList;pub use request::ChatCompletionRequest;pub use request::JsonSchemaObject;pub use request::ResponseFormat;pub use request::StreamOptions;pub use retry::RetryConfig;pub use types::ChatCompletion;pub use types::ChatCompletionChoice;pub use types::ChatCompletionChunk;pub use types::ChatCompletionTokenLogprob;pub use types::ChatMessage;pub use types::ChatMessageContent;pub use types::ChoiceLogprobs;pub use types::ContentPart;pub use types::EmbeddingResponse;pub use types::FunctionCall;pub use types::ImageUrl;pub use types::LlmResponse;pub use types::ModelInfo;pub use types::SimplifiedToolCall;pub use types::Tool;pub use types::ToolCall;pub use types::ToolChoice;pub use types::ToolFunction;pub use types::TopLogprob;pub use types::Usage;
Modules§
- api_
common - Shared API logic used by both sync and async clients.
- audio
- Audio API — TTS (text-to-speech) and STT (speech-to-text).
- error
- files
- Files API — upload, list, retrieve, delete files.
- images
- Images API — DALL-E image generation, editing, variations.
- models
- Models API — list and retrieve model information.
- request
- Request builder for OpenAI Chat Completions API.
- retry
- Automatic retry with exponential backoff.
- sse
- Minimal Server-Sent-Events (SSE) line framing, spec-compliant.
- thinking
- Thinking / reasoning extraction for OpenAI-compatible streams.
- tokens
- Token counting utility.
- types
- Shared types for the OpenAI API: chat messages, tool calls, completions, etc.
Structs§
- Chat
Chunk Stream - Iterator over raw, typed
ChatCompletionChunks from a streamed response. - Open
AiClient - An OpenAI-compatible API client.
- Stream
Handler
Functions§
- parse_
openai_ stream - Parse an OpenAI-style SSE chat stream from any reader.
- parse_
openai_ stream_ rich - Parse an OpenAI-style SSE chat stream with an optional-callback
StreamHandler.