Communitygithub.com

YepAPI/skills

GPT API 패턴, 함수 호출, Zod를 활용한 구조화된 출력, 스트리밍 및 토큰 관리

skills란 무엇인가요?

이 스킬은 OpenAI GPT API를 효과적으로 사용하기 위한 모범 사례와 패턴을 제공합니다. 개발자가 공식 `openai` 패키지를 사용하여 스트리밍 채팅, 함수 호출, 구조화된 출력을 구현하는 방법을 다루며, Zod를 활용한 JSON 스키마 기반의 응답 형식을 지원합니다. 또한 토큰 추정 및 컨텍스트 트리밍을 통한 토큰 관리, GPT-4o와 GPT-4o-mini 간의 모델 선택, 시스템 프롬프트 설정, 온도 조절, 속도 제한 처리에 대한 구체적인 지침을 포함합니다. 이 스킬은 Claude Code, Cursor, Codex와 같은 AI 에이전트 플랫폼에서 사용할 수 있으며, 견고하고 효율적인 GPT 기반 애플리케이션을 구축하려는 개발자에게 유용합니다.

지원 대상~Claude Code✓Codex CLI~Cursor
npx skills add https://github.com/YepAPI/skills/tree/HEAD/skills/openai-integration

즐겨 사용하는 AI에게 물어보기

이 에이전트 스킬이 미리 로드된 새 채팅을 엽니다.

문서

OpenAI 통합

규칙

  • 공식 openai 패키지 사용 — new OpenAI({ apiKey: process.env.OPENAI_API_KEY })
  • 채팅 스트리밍: stream: true와 async iterator 사용 — 사용자 대상 응답에서는 전체 완료를 기다리지 않음
  • 함수 호출: JSON Schema로 함수를 정의하고, 응답에서 tool_calls를 처리하며, 결과를 도구 메시지로 반환
  • 구조화된 출력: response_format: { type: "json_schema", json_schema: {...} } 또는 AI SDK와 함께 Zod 사용
  • 토큰 관리: 전송 전 토큰 추정 (문자당 약 4토큰), 제한 내에 맞추기 위해 컨텍스트 트리밍
  • 모델 선택: 복잡한 추론에는 gpt-4o, 간단한 작업에는 gpt-4o-mini — 설정 가능하게 만들기
  • 시스템 프롬프트를 첫 번째 메시지로 — 톤, 제약 조건 및 출력 형식 설정
  • 온도: 결정적 출력(데이터 추출)에는 0, 창의적 작업에는 0.7-1.0
  • 속도 제한: x-ratelimit-* 헤더 준수, 429 오류 시 지수 백오프 구현

패턴

// 스트리밍 완료
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);
}
// 함수 호출
const response = await openai.chat.completions.create({
  model: "gpt-4o",
  messages,
  tools: [{ type: "function", function: { name: "get_weather", parameters: schema } }],
});

피해야 할 것

  • API 키 하드코딩 — 항상 환경 변수 사용
  • 토큰 제한 무시 — 토큰을 계산하고 메시지를 사전에 트리밍
  • 간단한 작업에 gpt-4o 사용 — 비용 절감을 위해 gpt-4o-mini 사용
  • API 호출 시 오류 처리 누락 — 429, 500, 타임아웃 오류를 적절히 처리

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.

관련 스킬