FEATURED — Operating guide for agents using the OpenAI MCP server. Imperative voice. Follow it exactly.
openai — generation, embeddings, images, audio, and moderation via the OpenAI API (paired with the OpenAI MCP server).
Use OpenAI models to: generate and transform text, reason over problems, produce embeddings for search/RAG, generate images, synthesize/transcribe audio, and moderate content. Do this correctly, safely, and cheaply.
Use OpenAI when the task needs:
VariableRequiredPurposeOPENAI_API_KEYYesSecret key. Read from env only.OPENAI_ORGNoOpenAI-Organization header.OPENAI_PROJECTNoOpenAI-Project header.
Never accept or output the key. See §13.
ToolUse foropenai_chatClassic chat completion.openai_responsesNewer unified API (tools, structured output, reasoning).openai_embeddingsVectors for RAG/search.openai_image_generateImage generation.openai_moderationsFree content safety.openai_modelsList/inspect models (free).openai_requestGeneric passthrough to any endpoint (audio, files, batches, fine-tuning, vector stores).
Pick the cheapest model that does the job. Escalate only when output is demonstrably insufficient.
TierText modelsUse fornanogpt-4.1-nanoTrivial classification, tiny tasks.mini (default)gpt-4o-mini, gpt-4.1-miniMost chat, summarization, extraction.standardgpt-4.1, gpt-4oHigher-quality writing/analysis.reasoningo4-mini → o3Hard multi-step reasoning.frontiergpt-5Only when nothing else suffices.
Embeddings: text-embedding-3-small (1536, default) → text-embedding-3-large (3072).
Images: gpt-image-1. Moderation: omni-moderation-latest. TTS: gpt-4o-mini-tts. Transcription: whisper-1.
openai_chat for the broadly-compatible messages schema and simple flows.openai_responses for new work, reasoning models, structured output, and built-in tools.input) with text-embedding-3-small.These are paid calls. Follow every rule:
max_tokens (chat) / max_output_tokens (responses).gpt-4o-mini, text-embedding-3-small).usage on every response and report tokens./batches) for large non-interactive jobs (cheaper).openai_moderations / openai_models freely.openai_moderations (free) before sending to a paid model.flagged, refuse or sanitize — do not forward.ErrorReaction401 invalid_api_keyFix the key. Do NOT retry.429 rateBack off exponentially; cap attempts.429 insufficient_quotaStop; tell user to add credit. Retrying won't help.400 invalid paramsFix params; don't blindly retry.context_length_exceededTrim/summarize input or use bigger-context model.404 model_not_foundVerify with openai_models; pick valid model.
OPENAI_API_KEY.Authorization header.temperature (0–0.3) for consistent, repeatable output (extraction, classification).seed (when supported) for reproducibility.response_format (chat) or text.format (responses) with a json_schema to force valid JSON.max_tokens / max_output_tokens set?usage?openai_chat, gpt-4o-mini, max_tokens ~80, temp 0.2.openai_chat with context.openai_chat + response_format: json_object, validate.openai_request → /audio/speech, gpt-4o-mini-tts.openai_responses, o4-mini, set max_output_tokens.See recipes/ for full walkthroughs.
max_tokens → runaway cost.gpt-5/ o3 for trivial tasks → wasted money.401 → never works.Model names and pricing change. Periodically run openai_models to list current IDs, and confirm details against https://platform.openai.com/docs/api-reference.
Verification needed: confirm current models, params, and pricing with https://platform.openai.com/docs/api-reference.