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>
23 lines
546 B
JSON
23 lines
546 B
JSON
{
|
|
"id": "msg_01Aq9w938a90dw8q",
|
|
"type": "message",
|
|
"role": "assistant",
|
|
"model": "claude-sonnet-5",
|
|
"content": [
|
|
{
|
|
"type": "tool_use",
|
|
"id": "toolu_01A09q90qw90lq917835lq9",
|
|
"name": "side_quests",
|
|
"input": {"dinners": [{"name": "Sheet-pan gnocchi", "why": "Like your Regular tray bake, but quicker."}]}
|
|
}
|
|
],
|
|
"stop_reason": "tool_use",
|
|
"stop_sequence": null,
|
|
"usage": {
|
|
"input_tokens": 472,
|
|
"cache_creation_input_tokens": 0,
|
|
"cache_read_input_tokens": 0,
|
|
"output_tokens": 61
|
|
}
|
|
}
|