Expand description
§OpenModex SDK for Rust
Official Rust SDK for the OpenModex API.
OpenModex is a unified API gateway for accessing multiple LLM providers through a single OpenAI-compatible interface.
§Quick Start
use openmodex::{OpenModex, ChatCompletionRequest, ChatMessage, Error};
#[tokio::main]
async fn main() -> Result<(), Error> {
let client = OpenModex::new("omx_sk_...")?;
let response = client.chat().completions().create(
ChatCompletionRequest::new("gpt-4o")
.message(ChatMessage::user("Hello!"))
.temperature(0.7)
).await?;
println!("{}", response.choices[0].message.as_ref()
.and_then(|m| m.content.as_deref())
.unwrap_or(""));
Ok(())
}§Streaming
use openmodex::{OpenModex, ChatCompletionRequest, ChatMessage, Error};
use futures::StreamExt;
#[tokio::main]
async fn main() -> Result<(), Error> {
let client = OpenModex::new("omx_sk_...")?;
let mut stream = client.chat().completions().create_stream(
ChatCompletionRequest::new("gpt-4o")
.message(ChatMessage::user("Tell me a story"))
).await?;
while let Some(chunk) = stream.next().await {
let chunk = chunk?;
if let Some(content) = chunk.choices.first()
.and_then(|c| c.delta.content.as_ref())
{
print!("{content}");
}
}
Ok(())
}Structs§
- ApiError
- An error returned by the OpenModex API with status code and structured detail.
- Cache
Config - OpenModex cache configuration extension.
- Chat
Choice - A single choice in a chat completion response.
- Chat
Completion Chunk - A single chunk in a streaming chat completion response.
- Chat
Completion Request - Request body for
POST /v1/chat/completions. - Chat
Completion Response - Response from
POST /v1/chat/completions. - Chat
Completion Stream - A stream of
ChatCompletionChunks from a streaming chat completion request. - Chat
Completions - Chat completion operations.
- Chat
Message - A single message in a chat conversation.
- Chat
Service - Service for chat completion operations.
- Client
Builder - Builder for constructing a configured
OpenModexclient. - Comparison
Highlights - Winners in each comparison category.
- Comparison
Item - A single model in a side-by-side comparison.
- Comparison
Performance - Performance metrics in a model comparison.
- Comparison
Pricing - Pricing in a model comparison.
- Comparison
Quality - Quality scores in a model comparison.
- Completion
Choice - A single choice in a completion response.
- Completion
Request - Request body for
POST /v1/completions. - Completion
Response - Response from
POST /v1/completions. - Completion
Service - Service for legacy text completion operations.
- Embedding
Data - A single embedding vector.
- Embedding
Request - Request body for
POST /v1/embeddings. - Embedding
Response - Response from
POST /v1/embeddings. - Embedding
Service - Service for embedding operations.
- Modalities
- Input/output modalities of a model.
- Model
- A model available through the OpenModex API.
- Model
Compare Response - Response from
GET /v1/models/compare. - Model
List Response - Response from
GET /v1/models. - Model
Performance - Performance metrics for a model.
- Model
Pricing - Pricing information for a model.
- Model
Service - Service for model-related operations.
- Model
Usage Stats - Usage statistics for a model.
- Open
Modex - The OpenModex API client.
- Open
Modex Metadata - OpenModex-specific response metadata.
- Quality
Scores - Benchmark quality scores for a model.
- Routing
Config - OpenModex routing configuration extension.
- Stream
Choice - A single choice in a streaming chunk.
- Stream
Delta - The incremental content delta in a streaming chunk.
- Usage
- Token usage statistics.
Enums§
- Error
- The primary error type for the OpenModex SDK.
Constants§
- DEFAULT_
BASE_ URL - The default base URL for the OpenModex API.
- VERSION
- The SDK version.