Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
AI and LLM integration

OpenAI says the model is a chat model and not supported in the v1/completions endpoint

ErrorThis is a chat model and not supported in the v1/completions endpoint

Short answer

The v1/completions endpoint accepts completion models such as gpt-3.5-turbo-instruct. Chat models belong on v1/chat/completions. Find the call that still uses the completions endpoint, in the OpenAI SDK or in a LangChain class, and switch it to the chat call or the chat wrapper.

  • Applies to Python 3.12, openai 1.x, langchain-openai 1.x
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Search the project for the calls that hit the completions endpoint. Any hit that passes a chat model name is the culprit.

    grep -rnE "completions\.create|Completion\.create|import OpenAI|OpenAI\(" --include=*.py .
  2. 2Match what you see, then jump to its fix

    1. 1The code calls client.completions.create(...) with prompt=...The SDK call targets the completions endpointFix
    2. 2The code imports OpenAI from langchain_openai, not ChatOpenAIA LangChain class that wraps the completions endpointFix
    3. 3Your code or a tool you use must send a raw prompt stringYou really need a completion modelFix

What does the error look like?

  • This is a chat model and not supported in the v1/completions endpoint

Cause 1 of 3

The SDK call targets the completions endpoint

1Check

The reference for the completions endpoint lists gpt-3.5-turbo-instruct, davinci-002 and babbage-002 as its models, and shows the path POST /completions. Chat models are served by POST /chat/completions.

grep -rn "completions.create" --include=*.py .

2Fix

Use the chat call and send messages instead of a prompt string. The text of the reply is in the first choice.

from openai import OpenAI

client = OpenAI()
response = client.chat.completions.create(
    model="your-chat-model",
    messages=[{"role": "user", "content": "Hello!"}],
)
print(response.choices[0].message.content)

3Verify

The call returns text and no 404 or invalid request error.

python app.py

Confirmed by developers.openai.com

Did this fix it?

Cause 2 of 3

A LangChain class that wraps the completions endpoint

1Check

The langchain-openai reference describes the OpenAI class as a completion model integration, shown with gpt-3.5-turbo-instruct. ChatOpenAI is the class for chat models and sends its calls to chat completions.

grep -rn "from langchain_openai import" --include=*.py .

2Fix

Replace OpenAI with ChatOpenAI and keep your chat model name.

from langchain_openai import ChatOpenAI

llm = ChatOpenAI(model="your-chat-model")
print(llm.invoke("Hello!").content)

3Verify

invoke returns a message and no endpoint error.

python app.py

Confirmed by reference.langchain.com

Did this fix it?

Cause 3 of 3

You really need a completion model

1Check

The completions reference lists the models that work there. A chat model name is not among them.

grep -rn "model=" --include=*.py .

2Fix

Set the model to one of the listed completion models, for example gpt-3.5-turbo-instruct, and keep the completions call.

from openai import OpenAI

client = OpenAI()
out = client.completions.create(model="gpt-3.5-turbo-instruct", prompt="Say hello")
print(out.choices[0].text)

3Verify

The completions call returns text.

python app.py

Confirmed by developers.openai.com

Did this fix it?

How do I stop it coming back?

  • Read the model name and the endpoint together when you copy sample code.
  • Put the model name in one config value so a swap does not leave an old call behind.
  • In LangChain, use ChatOpenAI for chat models and OpenAI only for completion models.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.