Creates a new OpenAIAdapter instance.
OpenAI adapter configuration
ReadonlyproviderProvider identifier (e.g., 'anthropic', 'openai')
ReadonlymodelModel identifier (e.g., 'claude-sonnet-4', 'gpt-4o')
ReadonlycapabilitiesCapabilities this model supports
Protected ReadonlyloggerLogger for request/response logging
Protected ReadonlyconfigConfiguration for the adapter
Check if this adapter supports a specific capability.
The capability to check for
True if the capability is supported
ProtectedlogLog details about an outgoing request. Sanitizes sensitive information before logging.
The completion request to log
ProtectedlogLog details about a received response.
The completion response to log
ProtectedtransformTransform a provider-specific error into a standardized ModelError.
Maps common error patterns to appropriate error codes:
The original error from the provider
A standardized ModelError
Validates adapter configuration. Extends base validation with OpenAI-specific checks.
Send a completion request to OpenAI.
The completion request
Result with response or ModelError
Stream a completion request from OpenAI.
The completion request
Count tokens in text using OpenAI-specific estimation.
Text to count tokens for
Approximate token count
(#2529) List models served by this OpenAI-compatible endpoint.
Wraps GET /v1/models. Result is cached for LIST_MODELS_TTL_MS
so identity resolution doesn't round-trip on every adapter.
Concurrent callers share the in-flight promise.
Throws on non-2xx so the harness-side identity resolver knows to fall back to modelId parsing — silent empty-list returns would be indistinguishable from "this gateway has no models", which a misconfigured endpoint shouldn't be allowed to claim.
OpenAI model adapter.
Provides a unified interface for interacting with OpenAI's GPT models. Supports completion, streaming, tool use, and vision capabilities.
Example