Expand description
HTTP client for the OpenRouter chat-completions API (direct HTTP, no CLI subprocess). HTTP client for the OpenRouter chat-completions API.
Sends structured-output chat requests to the OpenAI-compatible endpoint
at openrouter.ai/api/v1/chat/completions and returns the parsed JSON
object the model produced under a strict json_schema response_format.
This mirrors crate::embedding_api for the embeddings endpoint: same
retry/backoff policy (immediate abort on 401/400/404, retry-after on
429, exponential backoff + jitter on 5xx) and the same minimal headers
(only Authorization: Bearer, no HTTP-Referer/X-Title). The shared
error envelope and backoff helper live in crate::openrouter_http
(GAP-SG-74).
v1.0.95 (ADR-0054): adds an OpenRouter REST transport for the enrich
JUDGE so structured extraction no longer requires a locally installed
claude / codex / opencode CLI subprocess.
v1.1.00 (GAP-SG-70/72-chat): the OpenAI-compatible contract surfaces
choices[].finish_reason and usage.{prompt_tokens,completion_tokens}.
finish_reason == "length" means the response was truncated because
max_tokens was too small — not a malformed generation.
OpenRouterChatClient::complete
now detects this BEFORE attempting JSON repair, grows max_tokens and
re-issues the request (bounded by
crate::constants::ENRICH_MAX_LENGTH_RETRIES), and always reports the
diagnostics (finish_reason, token counts) to the caller via
ChatCompletion on success or
ChatError on failure.
Structs§
- Chat
Completion - Successful
OpenRouterChatClient::completeresult (GAP-SG-72-chat). - Chat
Error OpenRouterChatClient::completefailure (GAP-SG-72-chat / GAP-SG-72 reauditor addendum).- Open
Router Chat Client - Process-wide OpenRouter chat client. Holds the model name so that callers
only thread the per-item prompt/schema/input through
Self::complete.