Skip to main content

Crate openmodex

Crate openmodex 

Source
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.
CacheConfig
OpenModex cache configuration extension.
ChatChoice
A single choice in a chat completion response.
ChatCompletionChunk
A single chunk in a streaming chat completion response.
ChatCompletionRequest
Request body for POST /v1/chat/completions.
ChatCompletionResponse
Response from POST /v1/chat/completions.
ChatCompletionStream
A stream of ChatCompletionChunks from a streaming chat completion request.
ChatCompletions
Chat completion operations.
ChatMessage
A single message in a chat conversation.
ChatService
Service for chat completion operations.
ClientBuilder
Builder for constructing a configured OpenModex client.
ComparisonHighlights
Winners in each comparison category.
ComparisonItem
A single model in a side-by-side comparison.
ComparisonPerformance
Performance metrics in a model comparison.
ComparisonPricing
Pricing in a model comparison.
ComparisonQuality
Quality scores in a model comparison.
CompletionChoice
A single choice in a completion response.
CompletionRequest
Request body for POST /v1/completions.
CompletionResponse
Response from POST /v1/completions.
CompletionService
Service for legacy text completion operations.
EmbeddingData
A single embedding vector.
EmbeddingRequest
Request body for POST /v1/embeddings.
EmbeddingResponse
Response from POST /v1/embeddings.
EmbeddingService
Service for embedding operations.
Modalities
Input/output modalities of a model.
Model
A model available through the OpenModex API.
ModelCompareResponse
Response from GET /v1/models/compare.
ModelListResponse
Response from GET /v1/models.
ModelPerformance
Performance metrics for a model.
ModelPricing
Pricing information for a model.
ModelService
Service for model-related operations.
ModelUsageStats
Usage statistics for a model.
OpenModex
The OpenModex API client.
OpenModexMetadata
OpenModex-specific response metadata.
QualityScores
Benchmark quality scores for a model.
RoutingConfig
OpenModex routing configuration extension.
StreamChoice
A single choice in a streaming chunk.
StreamDelta
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.