OpenAI’s Responses API builds on the strengths of the Chat Completions API while adding powerful, agentic features like web search, file search, and computer use. This makes it ideal for applications that need more than just text-based Q&A—especially those that need to access external resources or maintain multi-step conversations.
Key Differences at a Glance
- Built-In Tools: Web search, file search, and computer use are ready to go.
- Stateful by Default: Use
previous_response_id
to easily maintain context. - Event-Driven Responses: Rather than continuously appending tokens, you receive discrete, semantic events (e.g., text output or function calls).
- Storage: Responses are stored by default (disable by setting
store: false
). For Chat Completions, storage is optional or default depending on your account settings.
Code Comparison
Chat Completions Example
from openai import OpenAI
client = OpenAI()
completion = client.chat.completions.create(
model="gpt-4o",
messages=[
{
"role": "user",
"content": "Write a one-sentence bedtime story about a unicorn."
}
]
)
print(completion.choices[0].message.content)
Sample Response
[
{
"index": 0,
"message": {
"role": "assistant",
"content": "Under the soft glow of the moon, Luna the unicorn danced through fields of twinkling stardust, leaving trails of dreams for every child asleep."
},
"finish_reason": "stop"
}
]
Responses API Example
from openai import OpenAI
client = OpenAI()
response = client.responses.create(
model="gpt-4o",
input=[
{
"role": "user",
"content": "Write a one-sentence bedtime story about a unicorn."
}
]
)
print(response.output_text)
Sample Response
[
{
"id": "msg_67b73f697ba4819183a15cc17d011509",
"type": "message",
"role": "assistant",
"content": [
{
"type": "output_text",
"text": "Under the soft glow of the moon, Luna the unicorn danced through fields of twinkling stardust, leaving trails of dreams for every child asleep."
}
]
}
]
When to Use Which API
- Chat Completions: Perfect for simpler, text-focused applications that don’t require built-in tools or multi-step logic.
- Responses: Best for agentic workflows involving external actions (web lookups, file access, code execution) or complex state management. Recommended for new users.
Categories: