Add OpenAI-compatible llm.Provider adapter
internal/ai/llm/openai implements Provider over plain net/http against
POST {base}/chat/completions and GET {base}/models, with Bearer auth and
optional extra headers. Structured output uses response_format
json_schema (strict), json_object, or prompt-only with first-JSON-object
extraction, per the configured mode. Usage tokens, model and
finish_reason are parsed.
Errors map 401/403 to ErrAuth, 429 to ErrRateLimited with Retry-After
(seconds or HTTP-date), 408 and transport timeouts to ErrTimeout, and
other non-2xx statuses (and OpenRouter error bodies in a 2xx) to
ErrProvider with a key-redacted excerpt.
Contract tests replay OpenAI, OpenRouter and Ollama /v1 payloads from
httptest servers and assert the key and Authorization value never
appear in an error.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"data": [
|
||||
{
|
||||
"id": "openai/gpt-4o-mini",
|
||||
"canonical_slug": "openai/gpt-4o-mini",
|
||||
"name": "OpenAI: GPT-4o-mini",
|
||||
"created": 1721260800,
|
||||
"description": "GPT-4o mini is OpenAI's newest model after GPT-4 Omni.",
|
||||
"context_length": 128000,
|
||||
"architecture": {"modality": "text+image->text", "input_modalities": ["text", "image"], "output_modalities": ["text"], "tokenizer": "GPT"},
|
||||
"pricing": {"prompt": "0.00000015", "completion": "0.0000006"},
|
||||
"supported_parameters": ["max_tokens", "temperature", "response_format", "structured_outputs"]
|
||||
},
|
||||
{
|
||||
"id": "anthropic/claude-sonnet-5",
|
||||
"name": "Anthropic: Claude Sonnet 5",
|
||||
"created": 1767225600,
|
||||
"context_length": 200000,
|
||||
"supported_parameters": ["max_tokens", "temperature"]
|
||||
}
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user