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

Surface capability matrix

The Rust crate is the engine. The CLI calls it in-process, the proxy places an HTTP boundary around it, and the language clients speak that proxy contract.

Availability: Crate: in-process Rust · CLI: human workflow · Proxy: language-neutral server · Clients: proxy SDKs

Choose the boundary

Rust crateCLIHTTP proxyLanguage clients
Primary entrypointllmshim::completion / streamllmshim chatPOST /v1/chatchat / stream method
TransportIn-process calls; engine uses provider HTTPSTerminal around the engineJSON over HTTP; SSE for streamsHTTP/SSE to the proxy
Conversation stateYour applicationCLI processCallerCaller
Provider keysRust processCLI processProxy processProxy process, never client requests
Request contractOpenAI-shaped serde_json::ValueCLI-ownedCompact ChatRequestNative wrapper around ChatRequest
Non-stream resultOpenAI Chat Completions-shaped ValueRendered text/usageCompact ChatResponseNative wrapper around ChatResponse
StreamingNormalized OpenAI-delta JSON stringsRendered liveTyped SSEIterator, async iterator, channel, or block over typed events
Process behaviorEmbeddedOne CLI processLong-running serverPython/TS auto-start a bundled proxy; Go/Ruby connect to one

The caller resends conversation history; the CLI does that for its current interactive session. Native HTTP facades persist private replay metadata for issued reasoning and tool IDs; see native endpoints.

Where request features go

MeaningRust crateCLI chatHTTP proxyLanguage clients
Modeltop-level modelpicker and /modeltop-level modelrequest/model argument
Messagestop-level messagescurrent session historytop-level messagesrequest/messages argument
Portable controlstop-level fieldsCLI-selected defaultsfields under configconvenience arguments or config
Toolstop-level toolsno tool loopprovider_config.toolsPython/Ruby convenience; otherwise provider_config
Native controlstop-level x-openai, x-anthropic, or x-gemininot exposedsame namespace inside provider_configprovider_config
Structured output and shimsresponse_format, x-shimnot exposedsame top-level fieldstyped fields or convenience arguments
Fallbackscompletion_with_fallback configurationnot exposedtop-level fallbackfallback request field

The proxy's provider_config object is merged into the OpenAI-shaped engine request. That is why tools and native namespaces move under it without changing their inner shapes. Root model and messages are reserved. After route and alias resolution, the selected provider's namespace also cannot replace its native model or main history/input container. Native system and instruction controls remain supported. Explicit fallback targets receive the same checks, so a namespace is inert only when no selected fallback or route can activate it.

Build features

CapabilityCargo feature
Core translation, Rust API, and CLI chat/config commandsdefault build
Best-effort signature observationssignature-introspection (default on)
llmshim proxy and the Rust llmshim::proxy moduleproxy
Redis-coordinated proxy rate limitsredis-coordination (includes proxy)

The Homebrew package and the binaries bundled by Python and TypeScript include proxy support. Go and Ruby are pure HTTP clients and require a separately running proxy.

All language clients expose reasoning blocks and the tool-call signature object (data plus origin). Preserve those objects for replay.

Upstream response limits

The engine limits ordinary JSON completion bodies to 32 MiB and provider error bodies to 64 KiB, measured after HTTP decompression. It checks decoded chunks before adding them to its body buffer. Oversized final bodies return a fixed 502 error without including a truncated provider response. Retry bodies use the same error-body buffer limit; oversized bodies are dropped before another attempt.

These limits apply through the Rust completion API, CLI, proxy, and gateway. They bound decoded body bytes; JSON allocations and process memory have additional overhead. Successful raw responses returned by the low-level ShimClient::send API use the configured connect and response-header deadlines. After headers are returned, body size, decoding, idle time, total lifetime, and cancellation remain the caller's responsibility; llmshim does not attach a hidden body task or timer to that raw response.

Normal provider streams, ChatGPT's collected SSE replies, and native HTTP facades use one bounded SSE data decoder. It checks input before growing its line and frame buffers:

Per-stream limitMaximum
Decoded transport bytes32 MiB
Line content8 MiB
Frame bytes, with CRLF treated as one line ending8 MiB
Blank-line-delimited frames, including empty frames100,000
Input chunks, including empty chunks1,048,576
Retained normalized tool/reasoning/choice and collected ChatGPT stateestimated 16 MiB and 4,096 entries
Retained native usage/finality stateestimated 4 MiB and 4,096 entries

The decoder handles UTF-8 fragments, an initial byte-order mark, multiline data fields, comments, and LF/CRLF/CR line endings. Provider transforms consume the data fields; unused SSE metadata is discarded. Limits terminate the stream with a fixed error and release its input source. EOF does not manufacture a completed event from an unterminated frame. These are framing limits, not an RSS ceiling or a transport timeout.

The retained-state limits count only data held across events, including map and JSON-container overhead. Forwarded text is not charged after its chunk is released. Exceeding either retained-state limit ends the response with upstream stream retained state exceeds limit; no partial tool call or reasoning block is emitted. Rust embedders can inject smaller finite limits with StreamRetentionLimits for testing or a stricter deployment policy.

Collected text and refusals, reasoning text and opaque fragments, and native facade text append to their existing buffers. Completed reasoning snapshots still replace their matching block while preserving its original provenance.

For shape details, continue to the request field map and HTTP API.