Skip to main content

OpenAI (Text Completion)

LiteLLM supports OpenAI text completion models

note

OpenAI's model pages list the legacy Completions endpoint as not supported for current models. gpt-5.4, gpt-5.4-mini and gpt-5.4-nano still answer there as of October 2026, while gpt-5.5 and later answer 404. These are chat models, so the endpoint continues your prompt as plain text instead of replying to it, and the text can include the model's internal formatting tokens. LiteLLM does not track spend on this route yet. For chat-style answers and spend tracking, use the openai/ prefix, which also serves /completions requests.

Required API Keys​

import os 
os.environ["OPENAI_API_KEY"] = "your-api-key"

Usage​

import os 
from litellm import completion

os.environ["OPENAI_API_KEY"] = "your-api-key"

# openai call
response = completion(
model = "text-completion-openai/gpt-5.4-mini",
messages=[{ "content": "Hello, how are you?","role": "user"}]
)

Usage - LiteLLM Proxy Server​

Here's how to call OpenAI models with the LiteLLM Proxy Server

1. Save key in your environment​

export OPENAI_API_KEY=""

2. Start the proxy​

model_list:
- model_name: gpt-6-luna
litellm_params:
model: openai/gpt-6-luna # The `openai/` prefix will call openai.chat.completions.create
api_key: os.environ/OPENAI_API_KEY
- model_name: gpt-5.4-mini-completions
litellm_params:
model: text-completion-openai/gpt-5.4-mini # The `text-completion-openai/` prefix will call openai.completions.create
api_key: os.environ/OPENAI_API_KEY

3. Test it​

curl --location 'http://0.0.0.0:4000/chat/completions' \
--header 'Content-Type: application/json' \
--data ' {
"model": "gpt-5.4-mini-completions",
"messages": [
{
"role": "user",
"content": "what llm are you"
}
]
}
'

OpenAI Text Completion Models / Instruct Models​

Model NameFunction Call
gpt-5.4response = completion(model="text-completion-openai/gpt-5.4", messages=messages)
gpt-5.4-miniresponse = completion(model="text-completion-openai/gpt-5.4-mini", messages=messages)
gpt-5.4-nanoresponse = completion(model="text-completion-openai/gpt-5.4-nano", messages=messages)

OpenAI shuts down gpt-5.4-nano on April 1, 2027.

LiteLLM Enterprise
SSO/SAML, audit logs, spend tracking, multi-team management, and guardrails, built for production.
Learn more →