model-gateway-rs
model-gateway-rs is a Rust library that provides a minimal, LLM-centric interface with an OpenAI-compatible chat completions implementation.
Features
- Minimal
Llmtrait withchat_onceandchat_stream ChatCompletionsLlmimplementation usingv1/chat/completions- OpenAI-compatible text and image content for chat completions
- Async-friendly, built with
async-trait
Directory structure
src/
├── llm/ # LLM trait + chat completions implementation
├── model/ # Shared request/response data structures
└── lib.rs # Library entry point
Usage
Add to your Cargo.toml:
= { = "https://github.com/code-serenade/model-gateway-rs" }
Example (chat_completions):
use ;
async
Vision-capable OpenAI-compatible models can use image content parts:
let input = LlmInput ;
For providers that use an OpenAI SDK-style versioned base URL, pass that URL directly:
let llm = new?;
Reasoning models can use the OpenAI-compatible reasoning_effort parameter:
let llm = llm.with_reasoning_effort;
Provider-specific thinking parameters can be passed through as extra request body fields:
let llm = llm.with_extra_body_param?;
Some OpenAI-compatible providers expect SDK-style provider options under a
top-level extra_body object:
let llm = llm.with_nested_extra_body_param?;
The native Doubao/Volcengine Ark REST API accepts thinking as a top-level
request field:
use DoubaoLlm;
let llm = new?
.without_thinking;
Ollama uses its native /api/chat endpoint for thinking controls, not the
OpenAI-compatible endpoint:
use OllamaLlm;
let llm = new?
.without_thinking;
License
MIT