ADR 0007: Models are called over plain httpx, behind ModelInterface¶
Status: accepted
Context¶
M5 needs adapters for Anthropic and for OpenAI-compatible servers (which also covers local
models). The lock already contains the anthropic and openai SDKs, but only as transitive
dependencies of vibey-engine, at the versions that package pins. httpx is already a direct
dependency of the webhooks extra.
Decision¶
- Adapters use
httpxdirectly, not the vendor SDKs. Both APIs are one JSONPOSTfor a completion and one for a token count. - The transport is injected. An adapter takes an
httpx.Clientin its constructor, so tests pass one built onhttpx.MockTransportand record cassettes without patching, astests/architecture/test_no_patching.pyrequires. - Retry classification stays ours. An adapter maps status codes onto
TransientStageError(timeout, 429 without a spent-credit body, 5xx),CapacityExhaustedError(credit gone, 401/403) or an unrecoverable error, so the run machinery never sees a vendor exception. - The domain types are vendor-neutral:
ModelRequest,ModelResponse,ModelUsageandProviderDescriptor, with integer micro-dollar prices that round up.
Consequences¶
- The runtime dependency set does not grow, and a
vibey-enginerepin cannot change what the adapters send. - We own request shaping, header handling, prompt-cache markers and response parsing, and must
track API changes ourselves. Cassettes recorded from synthetic briefs and a
paidmarker for live checks keep that honest. - Streaming is not used: a book stage waits for a whole response, and the run journal stores the whole response.