openai-patterns

openai-patterns is a skill for Claude Code, Codex from chandrudp29/skillhub. It costs 31 tokens per session (1,251 once invoked), scanned A, original, MIT.

A practical guide to building software that uses the OpenAI API, including model choice, prompts, tool calls, streaming, errors, costs, and structured results.

In plain words
What is it for?
Use it when building or reviewing OpenAI API integrations, choosing a model, handling responses, or making API calls safer and easier to maintain.
Why use it?
It helps avoid common production problems such as unexpected costs, unparseable responses, exposed API keys, and unhandled rate limits.

Skill for Claude CodeCodex

Written for no agent in particular: nothing here depends on one. Also seen: positional $N argument; mentions Codex.

Good fit Use it when building or reviewing OpenAI API integrations, choosing a model, handling responses, or making API calls safer and easier to maintain.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/chandrudp29/skillhub/openai-patterns
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Any agent
npx skills add chandrudp29/skillhub --skill openai-patterns
Clone the repo
git clone --depth 1 https://github.com/chandrudp29/skillhub

Made for: Claude Code, Codex.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for openai-patterns

README.md
[![agentmods](https://agentmods.dev/badge/skills/chandrudp29/skillhub/openai-patterns/github.svg)](https://agentmods.dev/skills/chandrudp29/skillhub/openai-patterns)
Your own site
<a href="https://agentmods.dev/skills/chandrudp29/skillhub/openai-patterns"><img src="https://agentmods.dev/badge/skills/chandrudp29/skillhub/openai-patterns/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for openai-patterns

Your own site · 80×15
<a href="https://agentmods.dev/skills/chandrudp29/skillhub/openai-patterns"><img src="https://agentmods.dev/badge/skills/chandrudp29/skillhub/openai-patterns.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 31 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,251 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00031 $0.01251
Opus 5.5 $0.00012 $0.00500
Sonnet 5.5 $0.00006 $0.00250
Haiku 4.5 $0.00003 $0.00125

Measured 1mo ago against content hash 534213054da9, method: parsed. Prices are Anthropic first-party input rates as of 2026-10-07, from the pricing page.

Security

Grade A, and why

openai-patterns scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 1mo ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

skills/openai-patterns/SKILL.md · 167 lines

How it starts

The opening of the file, as written. The whole thing — 167 lines — stays where its author put it; the contents beside it link to each section on GitHub.

When to Use

Apply when building or reviewing code that calls the OpenAI API. Covers GPT-4, GPT-4o, o1, and Responses API.

Core Rules

  • Always handle rate limits with exponential backoff — they happen in production
  • Set max_tokens on every call — unbounded completions cause cost surprises
  • Log token usage per call — you need this for cost attribution and anomaly detection
  • Use structured outputs (response_format) when you need parseable data — regex on free text is fragile
  • Never hardcode API keys — use env vars, rotate quarterly

Model Selection

Model Best for Approx cost
gpt-4o-mini Classification, extraction, simple Q&A ~$0.15/1M input
gpt-4o Complex reasoning, code generation, long context ~$2.50/1M input
o1-mini Math, coding problems requiring multi-step reasoning ~$1.10/1M input
o1 Hardest reasoning tasks, research-grade ~$15/1M input

Rule: start with gpt-4o-mini and only upgrade if quality is insufficient. The gap is smaller than you think.

Basic Call Pattern

from openai import OpenAI
import os

client = OpenAI(api_key=os.environ["OPENAI_API_KEY"])

response = client.chat.completions.create(
    model="gpt-4o-mini",
    messages=[
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": "Explain transformer attention in one paragraph."},
    ],
    max_tokens=500,
    temperature=0.7,
)

text = response.choices[0].message.content
usage = response.usage  # prompt_tokens, completion_tokens, total_tokens

Structured Outputs

from pydantic import BaseModel

class SentimentResult(BaseModel):
    sentiment: Literal["positive", "negative", "neutral"]
    confidence: float
    reason: str

response = client.beta.chat.completions.parse(
    model="gpt-4o-mini",
    messages=[{"role": "user", "content": f"Analyze: {text}"}],
    response_format=SentimentResult,
)

result: SentimentResult = response.choices[0].message.parsed
# result.sentiment, result.confidence, result.reason — all typed

Read the full file on GitHub · 167 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 1mo ago First seen · 167 lines · 31 tokens per session scan A 534213054da9

Subscribe to this mod's changes

openai-patterns is a skill published in the GitHub repository chandrudp29/skillhub (14 stars, last pushed 3mo ago), licensed MIT. It adds 31 tokens to every session and 1,251 once invoked, about $0.0001 per session on Opus 5.5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.