Build agentic AI with OpenAI Responses API - stateful conversations with preserved reasoning, built-in tools (Code Interpreter, File Search, Web Search), and MCP integration. Use when: building agents with persistent reasoning, using server-side tools, or migrating from Chat Completions for better multi-turn performance.
/plugin marketplace add jezweb/claude-skills/plugin install jezweb-tooling-skills@jezweb/claude-skillsThis skill inherits all available tools. When active, it can use any tool Claude has access to.
README.mdreferences/built-in-tools-guide.mdreferences/mcp-integration-guide.mdreferences/migration-guide.mdreferences/reasoning-preservation.mdreferences/responses-vs-chat-completions.mdreferences/stateful-conversations.mdreferences/top-errors.mdrules/openai-responses.mdscripts/check-versions.shtemplates/background-mode.tstemplates/basic-response.tstemplates/cloudflare-worker.tstemplates/code-interpreter.tstemplates/file-search.tstemplates/image-generation.tstemplates/mcp-integration.tstemplates/package.jsontemplates/stateful-conversation.tstemplates/web-search.tsStatus: Production Ready Last Updated: 2026-01-09 API Launch: March 2025 Dependencies: openai@6.15.0 (Node.js) or fetch API (Cloudflare Workers)
OpenAI's unified interface for agentic applications, launched March 2025. Provides stateful conversations with preserved reasoning state across turns.
Key Innovation: Unlike Chat Completions (reasoning discarded between turns), Responses preserves the model's reasoning notebook, improving performance by 5% on TAUBench and enabling better multi-turn interactions.
vs Chat Completions:
| Feature | Chat Completions | Responses API |
|---|---|---|
| State | Manual history tracking | Automatic (conversation IDs) |
| Reasoning | Dropped between turns | Preserved across turns (+5% TAUBench) |
| Tools | Client-side round trips | Server-side hosted |
| Output | Single message | Polymorphic (8 types) |
| Cache | Baseline | 40-80% better utilization |
| MCP | Manual | Built-in |
npm install openai@6.15.0
import OpenAI from 'openai';
const openai = new OpenAI({ apiKey: process.env.OPENAI_API_KEY });
const response = await openai.responses.create({
model: 'gpt-5',
input: 'What are the 5 Ds of dodgeball?',
});
console.log(response.output_text);
Key differences from Chat Completions:
/v1/responses (not /v1/chat/completions)input (not messages)developer (not system)response.output_text (not choices[0].message.content)Use Responses:
Use Chat Completions:
Automatic State Management using conversation IDs:
// Create conversation
const conv = await openai.conversations.create({
metadata: { user_id: 'user_123' },
});
// First turn
const response1 = await openai.responses.create({
model: 'gpt-5',
conversation: conv.id,
input: 'What are the 5 Ds of dodgeball?',
});
// Second turn - model remembers context + reasoning
const response2 = await openai.responses.create({
model: 'gpt-5',
conversation: conv.id,
input: 'Tell me more about the first one',
});
Benefits: No manual history tracking, reasoning preserved, 40-80% better cache utilization
Conversation Limits: 90-day expiration
Server-side hosted tools eliminate backend round trips:
| Tool | Purpose | Notes |
|---|---|---|
code_interpreter | Execute Python code | Sandboxed, 30s timeout (use background: true for longer) |
file_search | RAG without vector stores | Max 512MB per file, supports PDF/Word/Markdown/HTML/code |
web_search | Real-time web information | Automatic source citations |
image_generation | DALL-E integration | DALL-E 3 default |
mcp | Connect external tools | OAuth supported, tokens NOT stored |
Usage:
const response = await openai.responses.create({
model: 'gpt-5',
input: 'Calculate mean of: 10, 20, 30, 40, 50',
tools: [{ type: 'code_interpreter' }],
});
Built-in support for Model Context Protocol (MCP) servers to connect external tools (Stripe, databases, custom APIs).
Basic MCP:
const response = await openai.responses.create({
model: 'gpt-5',
input: 'Roll 2d6 dice',
tools: [{
type: 'mcp',
server_label: 'dice',
server_url: 'https://example.com/mcp',
authorization: process.env.TOKEN, // ⚠️ NOT stored, required each request
}],
});
MCP Output Types:
mcp_list_tools - Tools discovered on servermcp_call - Tool invocation + resultmessage - Final responseKey Innovation: Model's internal reasoning state survives across turns (unlike Chat Completions which discards it).
Visual Analogy:
Performance: +5% on TAUBench (GPT-5) purely from preserved reasoning
Reasoning Summaries (free):
response.output.forEach(item => {
if (item.type === 'reasoning') console.log(item.summary[0].text);
if (item.type === 'message') console.log(item.content[0].text);
});
For long-running tasks, use background: true:
const response = await openai.responses.create({
model: 'gpt-5',
input: 'Analyze 500-page document',
background: true,
tools: [{ type: 'file_search', file_ids: [fileId] }],
});
// Poll for completion (check every 5s)
const result = await openai.responses.retrieve(response.id);
if (result.status === 'completed') console.log(result.output_text);
Timeout Limits:
Returns 8 output types instead of single message:
| Type | Example |
|---|---|
message | Final answer, explanation |
reasoning | Step-by-step thought process (free!) |
code_interpreter_call | Python code + results |
mcp_call | Tool name, args, output |
mcp_list_tools | Tool definitions from MCP server |
file_search_call | Matched chunks, citations |
web_search_call | URLs, snippets |
image_generation_call | Image URL |
Processing:
response.output.forEach(item => {
if (item.type === 'reasoning') console.log(item.summary[0].text);
if (item.type === 'web_search_call') console.log(item.results);
if (item.type === 'message') console.log(item.content[0].text);
});
// Or use helper for text-only
console.log(response.output_text);
Breaking Changes:
| Feature | Chat Completions | Responses API |
|---|---|---|
| Endpoint | /v1/chat/completions | /v1/responses |
| Parameter | messages | input |
| Role | system | developer |
| Output | choices[0].message.content | output_text |
| State | Manual array | Automatic (conversation ID) |
| Streaming | data: {"choices":[...]} | SSE with 8 item types |
Example:
// Before
const response = await openai.chat.completions.create({
model: 'gpt-5',
messages: [
{ role: 'system', content: 'You are a helpful assistant.' },
{ role: 'user', content: 'Hello!' },
],
});
console.log(response.choices[0].message.content);
// After
const response = await openai.responses.create({
model: 'gpt-5',
input: [
{ role: 'developer', content: 'You are a helpful assistant.' },
{ role: 'user', content: 'Hello!' },
],
});
console.log(response.output_text);
8 Common Errors:
1. Session State Not Persisting
const conv = await openai.conversations.create()), reuse conv.id for all turns2. MCP Server Connection Failed (mcp_connection_error)
fetch(), check token expiration3. Code Interpreter Timeout (code_interpreter_timeout)
background: true for extended timeout (up to 10 min)4. Image Generation Rate Limit (rate_limit_error)
5. File Search Relevance Issues
chunk.score > 0.76. Cost Tracking Confusion
store: false if not needed, monitor response.usage.tool_tokens7. Conversation Not Found (invalid_request_error)
openai.conversations.list() before using8. Tool Output Parsing Failed
response.output_text helper or iterate response.output.forEach(item => ...) checking item.type✅ Always:
background: true for tasks >30sauthorization tokens (NOT stored, required each request)response.usage.total_tokens for cost control❌ Never:
response.output_text helper)rate_limit_error, mcp_connection_error specifically)Official Docs:
Skill Resources: templates/, references/responses-vs-chat-completions.md, references/mcp-integration-guide.md, references/built-in-tools-guide.md, references/migration-guide.md, references/top-errors.md
This skill should be used when the user asks to "create a slash command", "add a command", "write a custom command", "define command arguments", "use command frontmatter", "organize commands", "create command with file references", "interactive command", "use AskUserQuestion in command", or needs guidance on slash command structure, YAML frontmatter fields, dynamic arguments, bash execution in commands, user interaction patterns, or command development best practices for Claude Code.
This skill should be used when the user asks to "create an agent", "add an agent", "write a subagent", "agent frontmatter", "when to use description", "agent examples", "agent tools", "agent colors", "autonomous agent", or needs guidance on agent structure, system prompts, triggering conditions, or agent development best practices for Claude Code plugins.
This skill should be used when the user asks to "create a hook", "add a PreToolUse/PostToolUse/Stop hook", "validate tool use", "implement prompt-based hooks", "use ${CLAUDE_PLUGIN_ROOT}", "set up event-driven automation", "block dangerous commands", or mentions hook events (PreToolUse, PostToolUse, Stop, SubagentStop, SessionStart, SessionEnd, UserPromptSubmit, PreCompact, Notification). Provides comprehensive guidance for creating and implementing Claude Code plugin hooks with focus on advanced prompt-based hooks API.