/** * OpenAI Provider Implementation * * Implements the Provider interface for OpenAI's Chat Completions API. * Handles message format translation between AgentRouter's internal format * (which uses Anthropic-style messages) and OpenAI's format. * * Key differences from Anthropic format: * - System prompt goes in messages array as role: "system" * - Tool schemas use "parameters" instead of "input_schema" * - Tool calls are in a separate "tool_calls" array, not content blocks * - Tool results use role: "tool" messages, not tool_result content blocks */ import { BaseProvider } from './base.js'; import type { CompletionRequest, CompletionResponse, StreamChunk, ProviderConfig } from '../types.js'; /** * OpenAI provider adapter. * * Translates between AgentRouter's internal message format and OpenAI's * Chat Completions API format. Supports both streaming and non-streaming * completion requests. */ export declare class OpenAIProvider extends BaseProvider { readonly name: string; private static readonly DEFAULT_BASE_URL; constructor(config: ProviderConfig); /** * Build headers for OpenAI API requests. * Adds organization header if configured. */ protected buildHeaders(): Record; /** * Execute a completion request and return the full response. */ complete(request: CompletionRequest): Promise; /** * Execute a streaming completion request. */ completeStream(request: CompletionRequest): AsyncIterable; /** * Check if the provider is available and configured correctly. */ healthCheck(): Promise; /** * Translate AgentRouter request to OpenAI format. * * Note: Newer OpenAI models (gpt-4o, gpt-4-turbo, o1, etc.) require * max_completion_tokens instead of max_tokens. We detect model type * and use the appropriate parameter. */ private translateRequest; /** * Check if we're using the actual OpenAI API (not a compatible third-party API). * Third-party OpenAI-compatible APIs (Z.AI, DeepSeek, local LLMs, etc.) typically * use the standard max_tokens parameter, not max_completion_tokens. */ private isActualOpenAIAPI; /** * Check if a model requires max_completion_tokens instead of max_tokens. * Newer OpenAI models (gpt-4o, gpt-4-turbo, gpt-5.x, o1, o3, etc.) use the new parameter. * * IMPORTANT: This only applies to the actual OpenAI API. Third-party OpenAI-compatible * APIs (Z.AI, DeepSeek, Ollama, etc.) use the standard max_tokens parameter. * * As of late 2024, most new OpenAI models require max_completion_tokens. * We default to using max_completion_tokens for any model that: * - Contains 'gpt-4o', 'gpt-4-turbo', 'gpt-5', 'o1', 'o3', or 'chatgpt' * - OR is NOT a legacy model (gpt-3.5, gpt-4-0314, gpt-4-0613) */ private modelRequiresMaxCompletionTokens; /** * Translate messages from AgentRouter format to OpenAI format. * * Key translations: * - Content blocks are flattened to strings * - tool_use blocks become tool_calls array on assistant messages * - tool_result blocks become separate role: "tool" messages */ private translateMessages; /** * Translate tools from AgentRouter format to OpenAI format. */ private translateTools; /** * Translate OpenAI response to AgentRouter format. */ private translateResponse; /** * Translate OpenAI streaming chunk to AgentRouter StreamChunk format. * * OpenAI streams deltas that need to be accumulated for tool calls. * Text content can be yielded immediately. */ private translateStreamChunk; } //# sourceMappingURL=openai.d.ts.map