Skip to main content

Module anthropic

Module anthropic 

Source
Expand description

Anthropic Messages API adapter.

One sync POST to https://api.anthropic.com/v1/messages per complete() call, JSON in / JSON out. Built on ureq for the transport and serde_json for the bodies — no async runtime, no SDK dependency.

§Auth + headers (current as of 2026-04, per the claude-api skill)

x-api-key: <user's key>
anthropic-version: 2023-06-01
content-type: application/json

Prompt caching is GA on Claude 4.x — no anthropic-beta header needed. The legacy prompt-caching-2024-07-31 header is a no-op today and we don’t send it.

§What we do NOT support yet (and why it’s fine)

  • Streaming. ask() is one-shot — caller waits for the full SQL string, then displays it. Streaming would complicate the sync return type for marginal UX gain on a small payload.
  • Tool use. The model emits free-form text wrapped in JSON; the caller parses it. Adding tools (so the model could “call run_query directly”) is a richer iteration that lives outside sqlrite-ask — it’d belong in sqlrite-mcp (Phase 7h).
  • Multi-turn. Stateless. Conversational refinement is its own UX problem (see docs/phase-7-plan.md Q9-adjacent).

Structs§

AnthropicProvider
Anthropic Messages API client. Stateless — one struct, many complete() calls. The agent (ureq client) is reused across calls so connection-pool / TLS-session-cache benefits accrue when the same AnthropicProvider makes repeat calls.