OpenAI says the model is a chat model and not supported in the v1/completions endpoint
This is a chat model and not supported in the v1/completions endpointShort 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.
Fix it fast
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 .2Match what you see, then jump to its fix
- 1
The code calls client.completions.create(...) with prompt=...The SDK call targets the completions endpointFix - 2
The code imports OpenAI from langchain_openai, not ChatOpenAIA LangChain class that wraps the completions endpointFix - 3
Your code or a tool you use must send a raw prompt stringYou really need a completion modelFix
- 1
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.pyConfirmed by developers.openai.com
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.pyConfirmed by reference.langchain.com
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.pyConfirmed by developers.openai.com
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:
- stegnor.comMy company site: 804 pages from a Python and Jinja generator, with 15 free browser tools.
- MenuloA restaurant discovery platform in Germany, kept current by a Python ingestion pipeline.
- ShopGoAn e-commerce aggregator with a Python scraping engine behind its catalog, past 10K Google Play downloads.
Related fixes
AI
Old openai.ChatCompletion or openai.Embedding code breaks on a new SDK
APIRemovedInV1
The Python SDK was rewritten in version 1.0.
2 causes, each with a fixAI
Azure OpenAI says the API deployment for this resource does not exist
The API deployment for this resource does not exist
Azure OpenAI does not take a model name in the model field.
2 causes, each with a fixAI
Azure OpenAI fails with an SSL certificate verification error
httpx.ConnectError: [SSL: CERTIFICATE_VERIFY_FAILED]
The client checks the endpoint's certificate against its CA bundle, which is certifi by default.
2 causes, each with a fixAI
The OpenAI client says the API key is missing
Missing credentials. Please pass an `api_key`
OpenAI() looks for an api_key argument first and then the OPENAI_API_KEY environment variable.
3 causes, each with a fixAI
TypeError when you index an OpenAI response like a dictionary
TypeError: 'ChatCompletion' object is not subscriptable
Since SDK 1.0 the OpenAI Python library returns Pydantic model objects instead of dictionaries, so response['choices'] fails.
2 causes, each with a fixAI
TypeError: Client.__init__() got an unexpected keyword argument 'proxies'
TypeError: Client.__init__() got an unexpected keyword argument 'proxies'
httpx 0.28.0 removed its deprecated proxies argument.
2 causes, each with a fix