Skip to main content

Overview

The OpenAI-compatible provider connects core-ai to third-party endpoints that implement the Chat Completions API. It accepts known nonstandard response fields used by gateways and inference servers. It provides models through the Chat Completions API with compatibility extensions enabled. Use @core-ai/openai for OpenAI’s Responses API, strict Chat Completions, embeddings, and image generation.

Installation

createOpenAICompat()

Options

string
API key sent to the compatible endpoint.
string
Base URL for the compatible Chat Completions endpoint.
OpenAI
A configured OpenAI SDK client.
boolean
Whether to extract nonstandard reasoning_content and reasoning response fields. Defaults to true.
'tool' | 'json-schema' | 'json-object'
How generateObject() and streamObject() request structured output. Defaults to tool for broad endpoint compatibility. Set this to json-schema when the endpoint supports strict JSON Schema response formats. Use json-object for endpoints that support JSON Mode without JSON Schema.
'max_tokens' | 'max_completion_tokens'
Request parameter used for maxTokens across this provider. When unset, known OpenAI models use their registered capability and unknown models use max_tokens.

Returns

OpenAICompatProvider with a single chatModel() method.

Generate text

Model capabilities

Each model exposes model.capabilities for unified reasoning, sampling, and tool-choice constraints:
Known OpenAI model IDs use the OpenAI registry. Other IDs use generic OpenAI-compatible fallback capabilities because the provider cannot infer vendor-specific behavior from an arbitrary endpoint. Treat those values as defaults and configure endpoint-specific wire behavior with structuredOutputMode, maxTokensParameter, and reasoning. The fallback includes 'image' and 'file' in modalities.input, so multimodal requests are forwarded to the endpoint rather than rejected locally. The reasoning provider option controls extraction of nonstandard response fields; it does not change model.capabilities.

Compatibility behavior

The provider follows the standard Chat Completions request and response shapes, then recognizes these additional reasoning output fields:
  • reasoning_content, used by DeepSeek, Qwen, GLM, vLLM, and SGLang
  • reasoning, used by OpenRouter
Non-streaming values become reasoning parts and populate result.reasoning. Streaming values emit reasoning-start, reasoning-delta, and reasoning-end events. Structured output uses a forced function tool by default because support for response_format.json_schema varies between compatible endpoints. Endpoints that implement strict JSON Schema output can opt in:
Endpoints that implement JSON Mode can use json-object. The provider adds the schema to the system message and sends response_format: { type: 'json_object' }:
Strict OpenAI Chat Completions does not expose reasoning text. Use createOpenAI().chat.chatModel() when you do not want compatibility extensions.

Provider-specific options

Pass Chat Completions options through providerOptions.openai:
Supported fields are store, serviceTier, parallelToolCalls, user, stopSequences, frequencyPenalty, presencePenalty, and seed. Known OpenAI models select their required token-limit parameter automatically. Unknown model IDs use max_tokens, which has the broadest compatibility. Set maxTokensParameter on createOpenAICompat() when every model exposed by the endpoint requires a different parameter.