---
title: "OpenAI Text Completion API with LiteLLM"
url: "/docs/providers/text_completion_openai"
canonical_url: "https://docs.litellm.ai/docs/providers/text_completion_openai"
type: "docs"
last_updated: "2026-11-24"
summary: "Send prompts to OpenAI's legacy Completions endpoint with gpt-5.4, gpt-5.4-mini and gpt-5.4-nano through text-completion-openai/, via the SDK or AI Gateway."
related:
  - "/docs/providers/openai/ultrafast"
  - "/docs/providers/anthropic"
---
# OpenAI Text Completion API with LiteLLM

> Index of all LiteLLM docs: https://docs.litellm.ai/llms.txt


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`](../text_completion.md) requests.

:::

### Required API Keys

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

### Usage
```python keep-model-ids
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

```bash
export OPENAI_API_KEY=""
```

### 2. Start the proxy 

**config.yaml**

```yaml keep-model-ids
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
```
**config.yaml - proxy all OpenAI models**

Use this to add all openai models with one API Key. **WARNING: This will not do any load balancing**
This means requests to `gpt-6.1-sol`, `gpt-6-luna` will all go through this route 

```yaml
model_list:
  - model_name: "*"             # all requests where model not in your config go to this deployment
    litellm_params:
      model: openai/*           # set `openai/` to use the openai route
      api_key: os.environ/OPENAI_API_KEY
```
**CLI**

```bash keep-model-ids
$ litellm --model text-completion-openai/gpt-5.4-mini

# Server running on http://0.0.0.0:4000
```

### 3. Test it

**Curl Request**

```shell keep-model-ids
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 v1.0.0+**

```python keep-model-ids
import openai
client = openai.OpenAI(
    api_key="anything",
    base_url="http://0.0.0.0:4000"
)

# request sent to model set on litellm proxy, `litellm --model`
response = client.chat.completions.create(model="gpt-5.4-mini-completions", messages = [
    {
        "role": "user",
        "content": "this is a test request, write a short poem"
    }
])

print(response)

```
**Langchain**

```python keep-model-ids
from langchain_openai import OpenAI

llm = OpenAI(
    base_url="http://0.0.0.0:4000", # set base_url to the LiteLLM Proxy
    api_key="anything",
    model="gpt-5.4-mini-completions",
    temperature=0.1
)

response = llm.invoke("test from litellm. tell me why it's amazing in 1 sentence")

print(response)
```

## OpenAI Text Completion Models / Instruct Models

| Model Name          | Function Call                                      |
|---------------------|----------------------------------------------------|
| gpt-5.4             | `response = completion(model="text-completion-openai/gpt-5.4", messages=messages)` |
| gpt-5.4-mini        | `response = completion(model="text-completion-openai/gpt-5.4-mini", messages=messages)` |
| gpt-5.4-nano        | `response = completion(model="text-completion-openai/gpt-5.4-nano", messages=messages)` |

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

## Related pages

- [Fast & Ultrafast mode](https://docs.litellm.ai/docs/providers/openai/ultrafast.md)
- [Anthropic](https://docs.litellm.ai/docs/providers/anthropic.md)
