linger-openai-sdk
Rust-native SDK for OpenAI APIs.
linger-openai-sdk provides typed request builders, typed responses, streaming
support, multipart uploads, structured errors, conservative retry handling,
redacted diagnostics, webhook verification, and a replaceable HTTP transport
boundary.
This crate is designed to follow current OpenAI API behavior while keeping the implementation idiomatic for Rust: async APIs, explicit error types, feature-gated transport, and forward-compatible public models.
Installation
[]
= "0.1"
Default features enable the reqwest transport with rustls:
[]
= { = "0.1", = ["reqwest-transport", "rustls-tls"] }
To provide your own transport implementation:
[]
= { = "0.1", = false }
Minimum supported Rust version: 1.82.
Quick Start
use ;
async
Client Configuration
Client::new uses the default reqwest transport:
use Client;
let client = new?;
Use ClientConfig when you need organization, project, base URL, or retry
policy configuration. Custom configuration is passed together with a transport:
use ;
let retry_policy = RetryPolicy ;
let config = builder
.api_key
.organization
.project
.base_url
.retry_policy
.build?;
let client =
with_config_and_transport;
Lower-level connection, request, and read timeouts can be configured on a custom
reqwest::Client, wrapped with ReqwestTransport::new(client).
Implemented API Areas
The current crate covers the main user-facing OpenAI API surfaces:
- Responses, including streaming, input token counting, and compaction
- Chat Completions and legacy Completions
- Embeddings and Moderations
- Models
- Files and multipart Uploads
- Images
- Audio speech, transcription, translation, voice consents, and custom voices
- Videos, including create, edit, extend, remix, content download, and characters
- Realtime sessions, transcription sessions, client secrets, and calls
- Vector Stores, files, search, and file batches
- Conversations and conversation items
- Assistants and Threads APIs where implemented
- Batches
- Fine-tuning jobs, checkpoints, permissions, and grader helpers
- Evals and eval runs
- Containers and container files
- Skills and skill versions
- ChatKit sessions and threads
- Webhook signature verification
Organization/Admin/Projects management APIs are outside the current supported scope. Live OpenAI API tests are opt-in only and are not required for normal crate builds.
Streaming
Streaming APIs return Rust streams whose items surface errors explicitly. The SDK parses Server-Sent Events incrementally instead of buffering a full stream.
use StreamExt;
use ;
async
Files and Uploads
File-like inputs use explicit upload wrappers so content type, file name, and bytes are visible at the call site.
use Bytes;
use ;
async
Large uploads can be created through client.uploads(), uploaded in parts, and
completed with explicit part IDs.
Errors
All SDK methods return Result<T, LingerError>. Errors are structured and keep
important diagnostics without flattening everything into strings.
use ;
OpenAI API errors preserve HTTP status, request id, selected response headers,
and OpenAI error fields such as type, code, param, and message where
available.
Webhooks
WebhookVerifier verifies OpenAI webhook signatures and can parse the payload
after successful verification.
use ;
use Value;
Webhook secrets and authorization headers are redacted from diagnostics.
Features
| Feature | Enabled by default | Description |
|---|---|---|
reqwest-transport |
yes | Default HTTP transport backed by reqwest. |
rustls-tls |
yes | Enables the rustls TLS backend for reqwest. |
native-tls |
no | Enables the native TLS backend for reqwest. |
Disable default features if you need a runtime-neutral build with a custom transport:
[]
= { = "0.1", = false }
Transport Boundary
Custom integrations can implement Transport:
use ;
use Future;
use Pin;
;
Safety and Diagnostics
The SDK avoids logging secrets or sensitive payloads by default. Diagnostics prefer request ids, HTTP status, endpoint metadata, retry information, and OpenAI error fields over raw payload dumps.
Redacted data includes API keys, authorization headers, webhook secrets, and sensitive organization/project headers.
Documentation
The crate documentation is available on docs.rs after publication:
https://docs.rs/linger-openai-sdk
The repository also includes detailed English and Chinese usage guides:
README_EN.md and README_CN.md.
License
Licensed under either of:
- Apache License, Version 2.0
- MIT license
at your option.