Skip to main content

Crate llmposter

Crate llmposter 

Source
Expand description

§llmposter

A fixture-driven mock server for LLM APIs. Speaks OpenAI Chat Completions, Anthropic Messages, Gemini generateContent, and OpenAI Responses API — both streaming (SSE) and non-streaming.

§Quick Start

use llmposter::{ServerBuilder, Fixture};

#[tokio::test]
async fn test_llm_client() {
    let server = ServerBuilder::new()
        .fixture(
            Fixture::new()
                .match_user_message("hello")
                .respond_with_content("Hi from the mock!"),
        )
        .build()
        .await
        .unwrap();

    // Point your LLM client at server.url() instead of the real API
    let base_url = server.url();
    // ... your client code here ...
}

§Features

  • 4 LLM API formats: OpenAI, Anthropic, Gemini, OpenAI Responses
  • Streaming & non-streaming: SSE and JSON-array responses
  • Fixture-driven: YAML files or programmatic builder API
  • Failure simulation: latency, truncation, disconnect, corruption, error codes
  • Stateful scenarios: multi-turn matching via named state machines
  • Request capture: verify what your client sent with server.get_requests()
  • Auth simulation: bearer tokens, OAuth2 mock server (default oauth feature)
  • Record & replay (VCR): proxy requests to the real provider API and save responses as replayable fixtures. The default record feature pulls in reqwest’s rustls TLS stack — disable via default-features = false if you don’t need recording and want the smaller dependency footprint.
  • Deterministic: fixed IDs, sequential counters, no randomness

§Modules

Re-exports§

pub use auth::AuthState;
pub use auth::TokenStatus;
pub use fixture::FailureConfig;
pub use fixture::Fixture;
pub use fixture::Refusal;
pub use fixture::ScenarioConfig;
pub use fixture::StreamingConfig;
pub use fixture::ToolCall;
pub use record::VcrMode;
pub use server::OAuthConfig;
pub use server::CapturedRequest;
pub use server::MockServer;
pub use server::RequestOutcome;
pub use server::ServerBuilder;

Modules§

auth
Bearer token authentication and OAuth2 middleware.
cli
CLI binary entry point and argument parsing.
fixture
Fixture types, matching logic, and YAML loading.
record
VCR record/replay: proxy unmatched requests to a real provider API and save the response as a replayable fixture in a cassette file (a YAML fixture file the recorder appends to). Enabled by the record feature.
server
Server builder, mock server, and request capture.

Enums§

Provider
Provider identifier — which endpoint was hit.