OpenAI's chat completions vs. completions endpoint

Key takeaways:

  • Chat completions use a series of messages, while completions API uses a single prompt.

  • Chat completions are designed for multi-turn conversations, while completions are for single-prompt tasks.

  • Chat completions access advanced models like GPT-4, while the completions API uses legacy models like GPT-3.5-turbo-instruct.

  • Chat completions excel in context-aware tasks, while completions work best for standalone tasks.

OpenAI provides two primary API endpoints for generating text from models: the completions endpoint and the chat completions endpoint. Both are designed to generate responses based on a given prompt, but they cater to different use cases, have distinct behaviors, and are structured in slightly different ways. In this Answer, we will explore the differences between these two endpoints.

Chat completions endpoint

Chat completions endpoint supports a more structured way of prompting the model by keeping track of message history (i.e., a conversation) and allows the model to generate more contextually aware, multi-turn conversationsMulti-turn conversations refer to interactions where context is maintained across multiple exchanges, allowing the conversation to build on previous responses..

Let’s examine the following code demonstrating a call to the chat completions API:

from openai import OpenAI
import os
client = OpenAI(api_key = os.environ["api_key_1"],)
my_response = client.chat.completions.create(
model="gpt-4o-mini",
response_format={ "type": "json_object" },
messages=[
{"role": "system", "content": "You are a helpful assistant. You are designed to output JSON."},
{"role": "user", "content": "Who won the cricket world cup in 1992?"}
]
)
print(my_response.choices[0].message.content)

Code explanation

  • Line 1: Import the OpenAI module and the OpenAI class.

  • Line 3: Instantiate an OpenAI client.

  • Line 5: Create a completion request using the chat completions method.

  • Line 6: Specify the GPT-3.5 model gpt-4o-mini and JSON response format.

  • Lines 8–10: Define two messages: one as the system’s role and another as the user’s query.

  • Line 13: Print the content of the first choice generated by the model.

Completions endpoint

The completions API endpoint underwent its last update in July 2023 and features a distinct interface compared to the new chat completions endpoint. This endpoint is now in legacy. Rather than receiving a list of messages as input, the endpoint requires a freeform text string referred to as a prompt.

The completions endpoint generates text continuations from a given prompt. It is ideal for writing, code generation, or any task where the goal is to continue a piece of text based on a single prompt.

Let’s examine the following code demonstrating a call to the completions endpoint:

from openai import OpenAI
import os
client = OpenAI(api_key = os.environ["api_key_1"],)
response = client.completions.create(
model="gpt-3.5-turbo-instruct",
prompt="Write a tagline for a fast food shop."
)
print(response)

Code explanation

  • Lines 1–3: Import the OpenAI module and instantiate an OpenAI client.

  • Line 5: Create a completion request using the completions.create() method.

  • Line 6: Specify the GPT-3.5 model gpt-3.5-turbo-instruct.

  • Line 7: Provide a prompt instructing the model to generate a tagline for a fast food shop.

Chat completions vs. completions endpoint

Understanding the difference between chat completions and completions endpoints is essential for optimizing the right tool for the task at hand. Chat completions are ideal for multi-turn conversations and maintaining context, while completions are more suited for isolated, single-prompt tasks. This knowledge not only helps in choosing the appropriate model for the task but also ensures cost efficiency and better performance based on the use case. The main differences between chat completions and completions API endpoint are the following:

  • Chat completions involve providing a conversation context through a sequence of messages, whereas Completions involve providing a single prompt without any conversation history.

Here’s a table that summarizes the key differences between chat completions and completions endpoints:

Key Differences

Chat Completions Endpoint

Completions Endpoints

Input Format

Series of messages (conversation context)

Single prompt (freeform text)

Usage

Optimized for multi-turn conversations, but suitable for single-turn tasks as well

Optimized for single-turn tasks with no conversation history

Model Access

Access to advanced models like GPT-4 and GPT-3.5-turbo

Access to legacy models like GPT-3.5-turbo-instruct

Response Format

Generates a response based on the message context

Generates a response based on a prompt without context

Main Use Case

Best for conversational or context-aware tasks

Best for standalone tasks that don’t require previous context

Model’s Role

Defined roles such as “system” and “user” for conversation

No predefined roles, only freeform instructions

Last Update

Ongoing development with newer models

Last update in July 2023 (legacy)

In conclusion, the chat completions endpoint is tailored for interactive, multi-turn conversations, making it ideal for applications like chatbots and virtual assistants, while the completions endpoint is best suited for single, one-off text generation tasks. Choosing between them depends on whether your use case requires maintaining context over multiple interactions or simply generating text based on a single prompt.

Frequently asked questions

Haven’t found what you were looking for? Contact Us


What is the difference between chat and completion in Azure OpenAI?

  • OpenAI Assistants API is like a toolkit for building your own custom language models.
  • Chat Completions API is like a pre-built library of language models that you can use out of the box.

Does the completions endpoint support multi-turn conversations?

The completions endpoint does not natively support multi-turn conversations. For multi-turn dialogues, the chat completions endpoint should be used.


Free Resources

Copyright ©2025 Educative, Inc. All rights reserved