Store Chat Messages & State Without Managing Infrastructure.Check Out DialogueDB
Skip to content

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 ​

ts
const llm = useLlm("openai.chat.v1", {
  model: "gpt-4o", // specify a model
});

OpenAi Chat By Model ​

ts
const llm = useLlm("openai.gpt-4o", {
  // other options,
  // no model needed, using gpt-4o
});
INFO
You can use the following models using this shorthand:
  • openai.gpt-6
  • openai.gpt-6-astra
  • openai.gpt-5.6
  • openai.gpt-5.6-terra
  • openai.gpt-5.6-luna
  • openai.gpt-5.5
  • openai.gpt-5.4
  • openai.gpt-5.4-mini
  • openai.gpt-5.2
  • openai.gpt-4.1
  • openai.gpt-4.1-mini
  • openai.gpt-4o
  • openai.gpt-4o-mini
  • openai.gpt-4.1-nanodeprecated
    Model "openai.gpt-4.1-nano" is deprecated and will shut down on 2026-10-23. Migrate to openai.gpt-5.6-luna.
  • openai.gpt-4deprecated
    Model "openai.gpt-4" is deprecated and will shut down on 2026-10-23. Migrate to openai.gpt-4o.
  • openai.gpt-5-minideprecated
    Model "openai.gpt-5-mini" is deprecated and will shut down on 2026-12-11. Migrate to "openai.gpt-5.6-terra".
  • openai.gpt-5-nanodeprecated
    Model "openai.gpt-5-nano" is deprecated and will shut down on 2026-12-11. Migrate to "openai.gpt-5.6-luna".
  • openai.o3deprecated
    Model "openai.o3" is deprecated and will shut down on 2026-12-11. Migrate to "openai.gpt-5.6".
  • openai.o4-minideprecated
    Shorthand "openai.o4-mini" is deprecated and may be removed in a future release.
Deprecated shorthands still resolve and will continue to work for now, but the underlying provider may stop accepting them at any time. Migrate to a current shorthand when you can.

Authentication ​

To authenticate, you need to provide an OpenAi API Key. You can provide the API key various ways, depending on your use case.

  1. Pass in as execute options using openAiApiKey
  2. Pass in as setup options using openAiApiKey
  3. 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.

ts
// 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.

OptionTypeDefaultDescription
modelstring—The model to use. Must be specified when using openai.chat.v1. Can be any valid chat model. See OpenAI Docs
openAiApiKeystringundefinedAPI key for OpenAi. See authentication
topPnumberundefinedMaps to top_p. See OpenAI Docs
stopSequencesarrayundefinedMaps to stop. See OpenAI Docs
frequencyPenaltynumberundefinedMaps to frequency_penalty. See OpenAI Docs
logitBiasobjectundefinedMaps to logit_bias. See OpenAI Docs
useJsonbooleanundefinedWhen true, sets response_format to json_object
effortstringundefinedMaps 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:

  • maxTokens is sent as max_completion_tokens instead of max_tokens. Reasoning models return a 400 on max_tokens (Use 'max_completion_tokens' instead). Non-reasoning models (gpt-4o, gpt-4.1, ...) still receive max_tokens.
  • temperature and topP are dropped unless effort is "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 when reasoning_effort is omitted. Pass effort: "none" on gpt-5.1 through gpt-5.6 to keep them. There is no way to keep them on gpt-6, o3, or o4-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.