Add internal/ai/llm/anthropic, an llm.Provider over plain net/http:
- POST {base}/v1/messages and GET {base}/v1/models with x-api-key and
anthropic-version 2023-06-01. An empty key, a non-positive
Config.MaxTokens and a base URL that is not absolute http(s), or that
carries userinfo, a query or a fragment, are construction errors.
- System text goes in the top-level system field. A Request with a
Schema becomes one tool whose input_schema is the schema, forced by
tool_choice; Response.JSON is that tool's input. Otherwise the text
blocks are Response.Text. Usage and stop_reason are parsed.
- ListModels follows has_more/after_id pages; Verify fetches one page
with limit=1.
- 401/403 map to ErrAuth, 429 and 529 to ErrRateLimited with
Retry-After, 408 and deadlines to ErrTimeout, other statuses to
ErrProvider with a redacted excerpt.
- Errors carry the OpenAI adapter's redaction chain, so no Error(),
Unwrap layer, errors.As target or %#v output holds the key.
Contract tests replay sanitized fixtures adapted from Anthropic's public
Messages API docs over httptest, covering tool-forced JSON, text, each
error mapping and key redaction with the keys x-api-key, anthropic,
HTTP, rate, a one-letter key and a URL-escaped key.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2 lines
148 B
JSON
2 lines
148 B
JSON
{"type": "error", "error": {"type": "authentication_error", "message": "invalid x-api-key: {{KEY}}"}, "request_id": "req_011CSHoEeqs5C35K2UUqR7Fy"}
|