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

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.

agentmods
npx agentmods add skills/chandrudp29/skillhub/openai-patterns
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.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.svg" alt="Measured on agentmods" 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. Scan, not verified.
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 $0.00031 $0.01251
Opus 5 $0.00015 $0.00626
Sonnet 5 $0.00006 $0.00250
Haiku 4.5 $0.00003 $0.00125

Measured 4d ago against content hash 534213054da9, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, 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 4d 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. 4d 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 (13 stars, last pushed 2mo ago), licensed MIT. It adds 31 tokens to every session and 1,251 once invoked, about $0.0002 per session on Opus 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.

Related

Other skills, from other repositories

prompt-optimization

Improve a prompt on the evaluations workbench through a measured loop. Score the baseline first, then duplicate the target column, form a hypothesis from failing rows, edit the copy's prompt draft, run, compare pass rate and cost, and repeat until the numbers hold. Use when the user asks to optimize or improve a…

langwatch/langwatch · 105 tokens

prompts

Version and manage your agent's prompts with LangWatch Prompts CLI. Use for both onboarding (set up prompt versioning for an entire codebase) and targeted operations (version a specific prompt, create a new prompt version). Supports Python and TypeScript.

langwatch/langwatch · 54 tokens

how-to-write-component

Use when implementing or refactoring React/TypeScript components and the task requires decisions about component ownership, feature boundaries, state, data flow, effects, or interaction ownership. Do not use for review-only requests, test-only work, copy-only edits, or styling-only changes.

langgenius/dify · 60 tokens

backend-code-review

Use only when the user explicitly requests a review or audit of backend code under api/. Supports pending-change, file-focused, and pasted-diff reviews. Do not use for implementation-only requests, diagnosis without review intent, frontend code, or backend code outside api/.

langgenius/dify · 60 tokens

e2e-cucumber-playwright

Use when writing, changing, or reviewing Cucumber and Playwright tests under e2e/, including feature files, step definitions, support code, scenario tags, locators, and assertions. Do not use for Vitest, React Testing Library, backend tests, or generic browser automation outside the E2E suite.

langgenius/dify · 73 tokens

frontend-code-review

Use only when the user explicitly requests a review or audit of frontend code under web/ or packages/dify-ui/. Supports pending-change, file-focused, and pasted-diff reviews. Do not use for implementation-only requests, diagnosis without review intent, or backend-only code.

langgenius/dify · 62 tokens