OpenAI
When using OpenAi models, llm-exe will make POST requests to https://api.openai.com/v1/chat/completions. All models are supported if you pass openai.chat.v1 as the first argument, and then specify a model in the options.
Basic Usage
OpenAi Chat
const llm = useLlm("openai.chat.v1", {
model: "gpt-4o", // specify a model
});OpenAi Chat By Model
const llm = useLlm("openai.gpt-4o", {
// other options,
// no model needed, using gpt-4o
});openai.gpt-6openai.gpt-6-astraopenai.gpt-5.6openai.gpt-5.6-terraopenai.gpt-5.6-lunaopenai.gpt-5.5openai.gpt-5.4openai.gpt-5.4-miniopenai.gpt-5.2openai.gpt-4.1openai.gpt-4.1-miniopenai.gpt-4oopenai.gpt-4o-miniopenai.gpt-4.1-nanodeprecatedopenai.gpt-4deprecatedopenai.gpt-5-minideprecatedopenai.gpt-5-nanodeprecatedopenai.o3deprecatedopenai.o4-minideprecated
Authentication
To authenticate, you need to provide an OpenAi API Key. You can provide the API key various ways, depending on your use case.
- Pass in as execute options using
openAiApiKey - Pass in as setup options using
openAiApiKey - Use a default key by setting an environment variable of
OPENAI_API_KEY
Generally you pass the LLM instance off to an LLM Executor and call that. However, it is possible to interact with the LLM object directly, if you wanted.
// call the LLM directly with a prompt
await llm.call(prompt);OpenAi-Specific Options
In addition to the generic options, the following options are OpenAi-specific and can be passed in when creating a llm function.
| Option | Type | Default | Description |
|---|---|---|---|
| model | string | — | The model to use. Must be specified when using openai.chat.v1. Can be any valid chat model. See OpenAI Docs |
| openAiApiKey | string | undefined | API key for OpenAi. See authentication |
| topP | number | undefined | Maps to top_p. See OpenAI Docs |
| stopSequences | array | undefined | Maps to stop. See OpenAI Docs |
| frequencyPenalty | number | undefined | Maps to frequency_penalty. See OpenAI Docs |
| logitBias | object | undefined | Maps to logit_bias. See OpenAI Docs |
| useJson | boolean | undefined | When true, sets response_format to json_object |
| effort | string | undefined | Maps to reasoning_effort. Valid values: "none", "minimal", "low", "medium", "high". Only sent for OpenAI reasoning models — any model whose name starts with gpt-5, gpt-6, o3, or o4; on any other model, or for a value outside that list, it is silently dropped. "none" is accepted only by gpt-5.1 through gpt-5.6; it is rejected with a 400 by the original gpt-5, gpt-5-mini, and gpt-5-nano (floor "minimal"), and by gpt-6, o3, and o4-mini (floor "low"). |
See OpenAI API Reference for details on these parameters.
Reasoning models (gpt-5*, gpt-6*, o3*, o4*) rewrite maxTokens, temperature, and topP
OpenAI's reasoning models reject the legacy Chat Completions parameters, so llm-exe adjusts the request for any model whose name starts with gpt-5, gpt-6, o3, or o4:
maxTokensis sent asmax_completion_tokensinstead ofmax_tokens. Reasoning models return a 400 onmax_tokens(Use 'max_completion_tokens' instead). Non-reasoning models (gpt-4o,gpt-4.1, ...) still receivemax_tokens.temperatureandtopPare dropped unlesseffortis"none". Reasoning models only accept the default sampling values while reasoning is active; gpt-5.5, gpt-5.6, gpt-6, and the o-series reject them even whenreasoning_effortis omitted. Passeffort: "none"on gpt-5.1 through gpt-5.6 to keep them. There is no way to keep them ongpt-6,o3, oro4-mini: those models reject non-default sampling values and also reject"none", so llm-exe always drops them there.
Both rules are specific to the OpenAI provider. The xAI and DeepSeek providers, which share the same mapper, forward these parameters unchanged.
