The Complete Production SOP: Deploying OpenAI SDK & Realtime API Expert in Codex, Claude Code, Cursor, and Windsurf
Production SOP to install and run the OpenAI SDK & Realtime API Expert skill in Codex, Claude Code, Cursor, and Windsurf with verified function calling schemas.
Technical Overview & Architectural Context
Without authoritative reference patterns, autonomous coding agents frequently hallucinate deprecated Chat Completions parameters, produce invalid JSON schemas for structured outputs, and botch the WebSocket/WebRTC handshake required by the OpenAI Realtime API. Generic LLMs often confuse legacy function calling with modern `tools` schemas, neglect strict mode requirements (`strict: true`), and misconfigure audio buffer frame rates (24kHz PCM16 vs G.711) in interactive voice pipelines. The `openai-docs` skill equips agents like Claude Code, Codex, Cursor, and Windsurf with deterministic boundaries for the OpenAI Responses API, Realtime protocol events (`session.update`, `response.create`), and strict parameter validation. By enforcing pre-flight repo inspection, JSON Schema Draft 2020-12 alignment, and sandboxed test-driven verification, this skill prevents broken streaming loops, context window saturation, and brittle client-side audio negotiations.
Prerequisites & Environment Requirements
Verified Search Intents & Long-Tail Queries Solved
This operational tutorial is engineered to provide deterministic solutions for these developer search queries:
Step-by-Step Execution Playbook
Local Skill Manifest Injection & Runtime Mounting
Mount the skill manifest into your project's local agent skills directory so Claude Code, Cursor, and Codex automatically pick up OpenAI API SOPs.
Autonomous agents scan designated configuration directories (`.agents/skills`, `.cursor/rules`, or `.claude/skills`) upon initialization. Placing the SKILL.md file inside the workspace ensures all runtime invocations regarding OpenAI Realtime and Responses APIs adhere strictly to latest schema definitions without polluting global user rules.
mkdir -p .agents/skills/openai-docs && curl -fsSL https://askills.dev/api/skills/openai-docs/raw -o .agents/skills/openai-docs/SKILL.md---
name: "openai-docs"
description: "Authoritative reference for OpenAI Responses API, Realtime Agents, and Codex system capabilities."
version: "1.0.0"
runtimes: ["codex", "claude-code", "cursor", "windsurf"]
---
# OpenAI SDK & Realtime API Expert
## Mandatory Schema Enforcement
- Every structured output function MUST use `strict: true` and include all declared properties in `required`.
- Realtime events must enforce 24kHz PCM16 or G.711 format alignment.
- Prefer the unified Responses API pattern over deprecated completion endpoints.In Cursor, symlink `.agents/skills/openai-docs/SKILL.md` to `.cursor/rules/openai-docs.mdc` with frontmatter `globs: "src/ai/**,src/realtime/**"` to conserve agent tokens when editing unrelated frontend code.
Ensure that your `.agents` directory is tracked by Git or added to your agent's workspace boundaries; if placed outside workspace root, strict container sandboxes will block agent read access.
Environment Secrets & SDK Compatibility Validation
Configure runtime credentials and verify the local SDK meets minimum version requirements for Realtime and Responses APIs.
The Realtime WebSocket and WebRTC APIs require specific OpenAI client configurations and ephemeral tokens. Claude Code and Codex should be prevented from embedding production API keys directly in test scripts or agent logs by verifying `.env.local` encapsulation.
test -f .env.local || cp .env.example .env.local && node -e "const v = require('openai/package.json').version; if (parseInt(v.split('.')[0]) < 4) process.exit(1); console.log('OpenAI SDK Version:', v)"OPENAI_API_KEY=sk-proj-xxxxxxxxxxxxxxxxxxxxxxxx
OPENAI_REALTIME_MODEL=gpt-4o-realtime-preview-2024-12-17
OPENAI_RESPONSES_MODEL=gpt-4oUse `openai.realtime.sessions.create()` on a backend route to generate ephemeral client keys for browser WebRTC connections rather than exposing your root API key to client agents.
Never run `export OPENAI_API_KEY` directly inside an agent prompt or commit `.env.local` to public repositories; verify `.env.local` is present in `.gitignore`.
Deterministic Trigger Invocation & Strict Function Schema
Instruct the agent using targeted intent triggers to generate a validated Realtime session handler with strict tool definitions.
When prompted, the agent loads `openai-docs` procedural rules, ensuring all function declarations supply `additionalProperties: false` alongside exhaustive `required` arrays, complying with OpenAI's strict JSON schema parser.
import { OpenAI } from 'openai';
export const sessionUpdateEvent = {
type: 'session.update',
session: {
modalities: ['text', 'audio'],
voice: 'verse',
input_audio_format: 'pcm16',
output_audio_format: 'pcm16',
input_audio_transcription: { model: 'whisper-1' },
turn_detection: { type: 'server_vad', threshold: 0.5, silence_duration_ms: 200 },
tools: [{
type: 'function',
name: 'fetch_order_status',
description: 'Retrieve real-time order status by identifier.',
strict: true,
parameters: {
type: 'object',
properties: {
order_id: { type: 'string', description: 'The tracking UUID' }
},
required: ['order_id'],
additionalProperties: false
}
}]
}
} as const;Specify exact WebSocket client events (e.g., `input_audio_buffer.append` and `response.create`) in prompt triggers to prevent the agent from writing non-standard event wrappers.
Omitting `additionalProperties: false` in function definitions will trigger a 400 Bad Request error from OpenAI's Structured Outputs engine.
Automated Linting, Schema Validation & Quality Gate
Execute strict schema verification and live WebSocket protocol assertions before accepting generated artifacts.
The skill mandates running local test suites to verify that Realtime event payloads conform to OpenAI's schema specifications before marking tasks as complete.
npm run test:realtime || pnpm test -- --filter=openai-realtimeimport { describe, it, expect } from 'vitest';
import { sessionUpdateEvent } from '../src/realtime/session-config';
describe('OpenAI Realtime Schema Gate', () => {
it('enforces strict flag and required properties on tools', () => {
const tool = sessionUpdateEvent.session.tools[0];
expect(tool.strict).toBe(true);
expect(tool.parameters.additionalProperties).toBe(false);
expect(tool.parameters.required).toContain('order_id');
});
});Instruct Claude Code or Codex to run `git diff --stat` after test execution to confirm no unauthorized modifications occurred outside targeted directories.
Real-World Scenario: Implement WebRTC Ephemeral Session Negotiation for OpenAI Realtime Voice
“Using the openai-docs skill, implement a Next.js App Router API route at /api/realtime/session that negotiates an ephemeral token with OpenAI Realtime API. Enforce pcm16 audio format, inject a strict weather_lookup tool, and test the response with Vitest.”
Runtime Troubleshooting & Failure Modes
Root Cause: OpenAI Structured Outputs and Realtime strict tools require 'additionalProperties: false' in all object nodes within the parameters schema.
parameters: { type: 'object', properties: { location: { type: 'string' } }, required: ['location'], additionalProperties: false }Root Cause: Mismatched audio encoding formats specified in 'session.update' payload (e.g., setting input to 'pcm16' while output is set to 'g711_ulaw').
session: { input_audio_format: 'pcm16', output_audio_format: 'pcm16' }Frequently Asked Questions (OpenAI SDK & Realtime API Expert SOP)
Q:Can I use OpenAI SDK & Realtime API Expert across Codex, Claude Code, and Cursor simultaneously?
Yes. The skill adheres to standard SKILL.md conventions. Placing it in `.agents/skills/openai-docs/` or referencing it in `.cursor/rules` enables native discovery across Claude Code, Codex Desktop, Cursor, and Windsurf.
Q:How does this skill prevent context window overflow during prolonged agent sessions?
The skill enforces modular function calling patterns and targeted code generation rules. Instead of streaming entire API specifications into every turn, it instructs the agent to consult scoped, on-demand schema subsets.
Q:Does this skill require escalated root or container permissions?
No. The skill is audited with a security score of 98/100, requires zero system daemon access, and operates strictly within workspace boundaries using user-level commands.
Ready to equip your autonomous agent with OpenAI SDK & Realtime API Expert?
Copy the complete audited SKILL.md specification or download the 1-click zip bundle directly from our verified registry.