Communitygithub.com

YepAPI/skills

GPT API-Muster, Funktionsaufrufe, strukturierte Ausgaben mit Zod, Streaming und Token-Verwaltung.

Was ist skills?

Diese Fähigkeit bietet einen umfassenden Leitfaden zur Integration der OpenAI-API in KI-Agenten und Entwickler-Tools. Sie behandelt Schlüsselkonzepte wie Streaming von Chat-Antworten mit asynchronen Iteratoren für eine reibungslose Benutzererfahrung, Funktionsaufrufe (Function Calling) mit JSON-Schema-Definitionen und die Verarbeitung von tool_calls. Darüber hinaus wird die Verwendung von strukturierten Ausgaben entweder über das response_format-Feld der API oder mit Zod und dem AI SDK erläutert, um vorhersagbare Ergebnisse zu erzielen. Die Fähigkeit betont wichtige Best Practices wie Token-Management (Schätzung von Token und Kürzung von Kontexten), Auswahl des geeigneten Modells (gpt-4o für komplexe Aufgaben, gpt-4o-mini für einfache) und ordnungsgemäße Fehlerbehandlung mit exponentieller Rückverzögerung bei Ratenbegrenzungen. Sie ist ideal für Entwickler, die mit OpenAI arbeiten und effiziente, zuverlässige und kostengünstige Integrationen erstellen möchten. Unterstützte Plattformen sind Claude Code, Cursor und Codex.

Funktioniert mit~Claude Code✓Codex CLI~Cursor
npx skills add https://github.com/YepAPI/skills/tree/HEAD/skills/openai-integration

In Ihrer bevorzugten KI fragen

Öffnet einen neuen Chat, in dem dieser Agent-Skill bereits geladen ist.

Dokumentation

OpenAI Integration

Regeln

  • Verwende das offizielle openai Paket — new OpenAI({ apiKey: process.env.OPENAI_API_KEY })
  • Streaming für Chat: stream: true mit asynchronem Iterator — warte niemals auf vollständige Antworten für benutzerseitige Antworten
  • Funktionsaufruf: Funktionen mit JSON-Schema definieren, tool_calls in der Antwort verarbeiten, Ergebnisse als Tool-Nachrichten zurückgeben
  • Strukturierte Ausgaben: response_format: { type: "json_schema", json_schema: {...} } oder Zod mit AI SDK verwenden
  • Token-Management: Token vor dem Senden schätzen (etwa 4 Zeichen pro Token), Kontext kürzen, um innerhalb der Limits zu bleiben
  • Modellauswahl: gpt-4o für komplexe Überlegungen, gpt-4o-mini für einfache Aufgaben — konfigurierbar machen
  • System-Prompt als erste Nachricht — Ton, Einschränkungen und Ausgabeformat festlegen
  • Temperatur: 0 für deterministische Ausgaben (Datenextraktion), 0,7-1,0 für kreative Aufgaben
  • Ratenbegrenzung: x-ratelimit-* Header beachten, exponentielle Rückverzögerung bei 429-Fehlern implementieren

Muster

// Streaming-Vervollständigung
const stream = await openai.chat.completions.create({
  model: "gpt-4o",
  messages,
  stream: true,
});

for await (const chunk of stream) {
  const content = chunk.choices[0]?.delta?.content || "";
  process.stdout.write(content);
}
// Funktionsaufruf
const response = await openai.chat.completions.create({
  model: "gpt-4o",
  messages,
  tools: [{ type: "function", function: { name: "get_weather", parameters: schema } }],
});

Vermeiden

  • Hartcodierte API-Schlüssel — immer Umgebungsvariablen verwenden
  • Token-Limits ignorieren — Token zählen und Nachrichten proaktiv kürzen
  • gpt-4o für triviale Aufgaben verwenden — gpt-4o-mini nutzen, um Kosten zu sparen
  • Fehlende Fehlerbehandlung bei API-Aufrufen — 429-, 500- und Timeout-Fehler elegant behandeln

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

YepAPI/skills

WCAG 2.1 AA — semantic HTML, keyboard navigation, screen readers.

YepAPI/skills

Experiment setup, variant splitting, statistical significance, and feature flag integration.

YepAPI/skills

CRUD generators, data tables, user management, role-based access, and bulk operations.

YepAPI/skills

Monitor what ChatGPT and Gemini say about your brand using YepAPI.

YepAPI/skills

Queue workers with BullMQ/Inngest/Trigger.dev, job retries, dead letter queues, concurrency.

YepAPI/skills

Commander.js, interactive prompts with Clack, spinners, colors, config files, exit codes, and npm publishing.

YepAPI/skills

cmdk integration, Cmd+K trigger, fuzzy search, grouped actions, keyboard navigation, and dynamic action registration.

YepAPI/skills

Content planning with trend and sentiment data from YepAPI.

YepAPI/skills

Content calendar, keyword-driven planning, and content briefs.

YepAPI/skills

Theme switching with CSS variables, system preference detection, next-themes, and persistence.

YepAPI/skills

Threaded comments, @mentions, reactions, moderation queue, optimistic UI, and cursor pagination.

YepAPI/skills

Competitive analysis between domains using YepAPI.

YepAPI/skills

Layout grids, KPI cards, data tables with sorting/filtering, sidebar navigation, and responsive breakpoints.

YepAPI/skills

Data encryption — TLS everywhere, AES-256-GCM for PII, bcrypt passwords, encrypted backups.

YepAPI/skills

Chart patterns with Recharts/Nivo/D3, responsive containers, color scales, and accessibility.

YepAPI/skills

Drizzle schema definition, push vs migrate, type-safe queries, relations, transactions, and prepared statements.

YepAPI/skills

Upload handling, resize/compress, CDN delivery, blur placeholders, and next/image patterns.

YepAPI/skills

Local business and Google Maps research using YepAPI.

YepAPI/skills

Cursor-based pagination, IntersectionObserver, virtualized lists with @tanstack/react-virtual, and scroll position restoration.

YepAPI/skills

Chat UI components, streaming responses with AI SDK, context window management, and RAG patterns.

Verwandte Skills