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

apiKey
string
API key sent to the compatible endpoint.
baseURL
string
Base URL for the compatible Chat Completions endpoint.
client
OpenAI
A configured OpenAI SDK client.
reasoning
boolean
Whether to extract nonstandard reasoning_content and reasoning response fields. Defaults to true.
structuredOutputMode
'tool' | 'native'
How generateObject() and streamObject() request structured output. Defaults to tool for broad endpoint compatibility. Set this to native when the endpoint supports strict JSON Schema response formats.

Returns

OpenAICompatProvider with a single chatModel() method.

Generate text

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 native strict JSON Schema output can opt in:
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.