Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Chat Models

Synaptic supports multiple LLM providers through the ChatModel trait defined in synaptic-core. Each provider lives in its own crate, giving you a uniform interface for sending messages and receiving responses -- whether you are using OpenAI, Anthropic, Gemini, or a local Ollama instance.

Providers

Each provider adapter lives in its own crate. You enable only the providers you need via feature flags:

ProviderAdapterCrateFeature
OpenAIOpenAiChatModelsynaptic-openai"openai"
AnthropicAnthropicChatModelsynaptic-anthropic"anthropic"
Google GeminiGeminiChatModelsynaptic-gemini"gemini"
Ollama (local)OllamaChatModelsynaptic-ollama"ollama"
use std::sync::Arc;
use synaptic::openai::OpenAiChatModel;

let model = OpenAiChatModel::new("gpt-4o");

For testing, use ScriptedChatModel (returns pre-defined responses) or FakeBackend (simulates HTTP responses without network calls).

Wrappers

Synaptic provides composable wrappers that add behavior on top of any ChatModel:

WrapperPurpose
RetryChatModelAutomatic retry with exponential backoff
RateLimitedChatModelConcurrency-based rate limiting (semaphore)
TokenBucketChatModelToken bucket rate limiting
StructuredOutputChatModel<T>JSON schema enforcement for structured output
CachedChatModelResponse caching (exact-match or semantic)
BoundToolsChatModelAutomatically attach tool definitions to every request

All wrappers implement ChatModel, so they can be stacked:

use std::sync::Arc;
use synaptic::models::{RetryChatModel, RetryPolicy, RateLimitedChatModel};

let model: Arc<dyn ChatModel> = Arc::new(base_model);
let with_retry = Arc::new(RetryChatModel::new(model, RetryPolicy::default()));
let with_rate_limit = RateLimitedChatModel::new(with_retry, 5);

Guides