[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M6EFQ3ZCNR30H5P145HDQ29Y":3,"skill-same:01M6EFQ3ZCNR30H5P145HDQ29Y":48},{"skillNo":4,"name":5,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":7,"ownerLogin":8,"ownerAvatarUrl":9,"ownerAccountNo":10,"ownerDisplayName":11,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":15,"categories":16,"keywords":17,"publishedAt":21,"linkOnly":22,"markdownContent":23,"markdownBody":23,"frontMatter":24,"refName":25,"commitSha":26,"skillDirectory":27,"forksCount":28,"repositoryHtmlUrl":29,"repositoryHomepageUrl":30,"ownerHtmlUrl":31,"ownerBlogUrl":6,"ownerDescription":32,"updatedAt":33,"install":34,"resources":47},"01M6EFQ3ZCNR30H5P145HDQ29Y","openai-sdk",null,"ComeOnOliver\u002Fskillshub","ComeOnOliver","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F43215937?v=4","01M6E5JNFECJAAVFE0W7SMWWD2","Haoran Shu","01M6E5JNNDQS7AJZDYFQ8TPZCK",66,"MIT","https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002FTerminalSkills\u002Fskills\u002Fopenai-sdk\u002FSKILL.md",[],[18,19,20],"sdk","openai","openai sdk","2026-11-10 10:12:30",false,"# OpenAI SDK\n\n## Overview\n\nThe OpenAI SDK provides access to GPT-4o, o1, DALL-E 3, Whisper, and embedding models. This skill covers the Chat Completions API (text generation, conversation, function calling), streaming responses, vision (image understanding), embeddings, the Assistants API (stateful agents), DALL-E image generation, Whisper transcription, and content moderation. Examples in both TypeScript\u002FNode.js and Python.\n\n## Instructions\n\n### Step 1: Installation and Setup\n\n```bash\n# Node.js\nnpm install openai\n\n# Python\npip install openai\n```\n\n```typescript\n\u002F\u002F lib\u002Fopenai.ts — Client initialization\nimport OpenAI from 'openai'\n\nconst openai = new OpenAI({\n  apiKey: process.env.OPENAI_API_KEY,    \u002F\u002F or set OPENAI_API_KEY env var\n})\n```\n\n### Step 2: Chat Completions\n\n```typescript\n\u002F\u002F chat.ts — Basic chat completion and conversation\nimport OpenAI from 'openai'\n\nconst openai = new OpenAI()\n\n\u002F\u002F Single message\nconst response = await openai.chat.completions.create({\n  model: 'gpt-4o',\n  messages: [\n    { role: 'system', content: 'You are a helpful coding assistant.' },\n    { role: 'user', content: 'Write a Python function to merge two sorted lists.' },\n  ],\n  temperature: 0.7,       \u002F\u002F 0 = deterministic, 2 = creative\n  max_tokens: 1000,\n})\n\nconsole.log(response.choices[0].message.content)\n\n\u002F\u002F Multi-turn conversation (maintain message history)\nconst messages: OpenAI.ChatCompletionMessageParam[] = [\n  { role: 'system', content: 'You are a data analysis assistant.' },\n]\n\nasync function chat(userMessage: string) {\n  messages.push({ role: 'user', content: userMessage })\n\n  const response = await openai.chat.completions.create({\n    model: 'gpt-4o',\n    messages,\n  })\n\n  const assistantMessage = response.choices[0].message\n  messages.push(assistantMessage)\n  return assistantMessage.content\n}\n```\n\n### Step 3: Streaming Responses\n\n```typescript\n\u002F\u002F stream.ts — Stream chat completions for real-time UI\nconst stream = await openai.chat.completions.create({\n  model: 'gpt-4o',\n  messages: [{ role: 'user', content: 'Explain quantum computing in simple terms.' }],\n  stream: true,\n})\n\nfor await (const chunk of stream) {\n  const content = chunk.choices[0]?.delta?.content || ''\n  process.stdout.write(content)    \u002F\u002F stream to terminal\u002FUI\n}\n```\n\n```typescript\n\u002F\u002F Next.js streaming API route\n\u002F\u002F app\u002Fapi\u002Fchat\u002Froute.ts — Server-sent events for streaming to frontend\nimport { OpenAIStream, StreamingTextResponse } from 'ai'    \u002F\u002F Vercel AI SDK helper\n\nexport async function POST(req: Request) {\n  const { messages } = await req.json()\n\n  const response = await openai.chat.completions.create({\n    model: 'gpt-4o',\n    messages,\n    stream: true,\n  })\n\n  const stream = OpenAIStream(response)\n  return new StreamingTextResponse(stream)\n}\n```\n\n### Step 4: Function Calling (Tool Use)\n\n```typescript\n\u002F\u002F function_calling.ts — Let GPT call your functions\nconst tools: OpenAI.ChatCompletionTool[] = [\n  {\n    type: 'function',\n    function: {\n      name: 'get_weather',\n      description: 'Get current weather for a city',\n      parameters: {\n        type: 'object',\n        properties: {\n          city: { type: 'string', description: 'City name' },\n          units: { type: 'string', enum: ['celsius', 'fahrenheit'] },\n        },\n        required: ['city'],\n      },\n    },\n  },\n  {\n    type: 'function',\n    function: {\n      name: 'search_database',\n      description: 'Search the product database',\n      parameters: {\n        type: 'object',\n        properties: {\n          query: { type: 'string' },\n          category: { type: 'string' },\n          max_price: { type: 'number' },\n        },\n        required: ['query'],\n      },\n    },\n  },\n]\n\nconst response = await openai.chat.completions.create({\n  model: 'gpt-4o',\n  messages: [{ role: 'user', content: 'What is the weather in Tokyo?' }],\n  tools,\n  tool_choice: 'auto',\n})\n\n\u002F\u002F Handle function call\nconst toolCall = response.choices[0].message.tool_calls?.[0]\nif (toolCall) {\n  const args = JSON.parse(toolCall.function.arguments)\n  \u002F\u002F Execute the actual function\n  const result = await getWeather(args.city, args.units)\n\n  \u002F\u002F Send result back to GPT\n  const finalResponse = await openai.chat.completions.create({\n    model: 'gpt-4o',\n    messages: [\n      { role: 'user', content: 'What is the weather in Tokyo?' },\n      response.choices[0].message,\n      { role: 'tool', tool_call_id: toolCall.id, content: JSON.stringify(result) },\n    ],\n    tools,\n  })\n}\n```\n\n### Step 5: Embeddings\n\n```typescript\n\u002F\u002F embeddings.ts — Generate embeddings for semantic search\nconst response = await openai.embeddings.create({\n  model: 'text-embedding-3-small',    \u002F\u002F 1536 dimensions, cheapest\n  input: 'How to deploy a Node.js app to production',\n})\n\nconst embedding = response.data[0].embedding    \u002F\u002F number[] of length 1536\n\n\u002F\u002F Batch embeddings\nconst batchResponse = await openai.embeddings.create({\n  model: 'text-embedding-3-small',\n  input: [\n    'First document text',\n    'Second document text',\n    'Third document text',\n  ],\n})\n\u002F\u002F batchResponse.data[0].embedding, batchResponse.data[1].embedding, etc.\n```\n\n### Step 6: Vision (Image Understanding)\n\n```typescript\n\u002F\u002F vision.ts — Analyze images with GPT-4o\nconst response = await openai.chat.completions.create({\n  model: 'gpt-4o',\n  messages: [{\n    role: 'user',\n    content: [\n      { type: 'text', text: 'What is in this image? Describe in detail.' },\n      { type: 'image_url', image_url: { url: 'https:\u002F\u002Fexample.com\u002Fphoto.jpg' } },\n    ],\n  }],\n})\n\n\u002F\u002F Base64 image (from file upload)\nconst base64Image = fs.readFileSync('photo.jpg').toString('base64')\nconst response2 = await openai.chat.completions.create({\n  model: 'gpt-4o',\n  messages: [{\n    role: 'user',\n    content: [\n      { type: 'text', text: 'Extract all text from this receipt.' },\n      { type: 'image_url', image_url: { url: `data:image\u002Fjpeg;base64,${base64Image}` } },\n    ],\n  }],\n})\n```\n\n### Step 7: Structured Outputs\n\n```typescript\n\u002F\u002F structured.ts — Get JSON output matching a schema\nconst response = await openai.chat.completions.create({\n  model: 'gpt-4o',\n  messages: [{ role: 'user', content: 'Extract info from: John Smith, 35, Software Engineer at Google, lives in SF' }],\n  response_format: {\n    type: 'json_schema',\n    json_schema: {\n      name: 'person_info',\n      schema: {\n        type: 'object',\n        properties: {\n          name: { type: 'string' },\n          age: { type: 'number' },\n          job_title: { type: 'string' },\n          company: { type: 'string' },\n          city: { type: 'string' },\n        },\n        required: ['name', 'age', 'job_title', 'company', 'city'],\n      },\n    },\n  },\n})\n\u002F\u002F Guaranteed to match the schema\nconst person = JSON.parse(response.choices[0].message.content!)\n```\n\n## Examples\n\n### Example 1: Build a customer support chatbot with function calling\n**User prompt:** \"Build a chatbot for our e-commerce site that can check order status, search products, and answer FAQs using our knowledge base.\"\n\nThe agent will:\n1. Define tools for `check_order_status`, `search_products`, and `search_knowledge_base`.\n2. Create a chat endpoint with streaming for real-time responses.\n3. Implement the tool execution loop (GPT calls tool → execute → send result back).\n4. Add conversation history management for multi-turn interactions.\n\n### Example 2: Build a document analysis pipeline\n**User prompt:** \"Users upload contracts (PDF\u002Fimages). Extract key terms, dates, and parties, then generate a structured summary.\"\n\nThe agent will:\n1. Use vision API to extract text from document images.\n2. Use structured outputs to extract entities into a typed JSON schema.\n3. Generate a plain-language summary with a system prompt tuned for legal documents.\n\n## Guidelines\n\n- Use `gpt-4o` for most tasks — it's the best balance of quality, speed, and cost. Use `gpt-4o-mini` for simple tasks where cost matters.\n- Always set a `system` message to define the assistant's behavior, constraints, and output format.\n- Use structured outputs (`response_format: json_schema`) when you need reliable JSON — it guarantees schema compliance, unlike asking for JSON in the prompt.\n- For function calling, define clear `description` fields — GPT uses these to decide when to call each function.\n- Use streaming for any user-facing chat interface — the perceived latency drops dramatically when users see tokens appear in real-time.\n- Set `temperature: 0` for deterministic tasks (classification, extraction, code generation) and `0.7-1.0` for creative tasks (writing, brainstorming).\n- Track token usage via `response.usage` for cost monitoring. Embedding and completion costs differ significantly.\n",{},"main","def8531e65114c0fca8fb8551c1871ee0eed705c","skills\u002FTerminalSkills\u002Fskills\u002Fopenai-sdk",24,"https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub","https:\u002F\u002Fskillshub.wtf","https:\u002F\u002Fgithub.com\u002FComeOnOliver","AI & Blockchain Engineer\r\n","2026-06-24 22:07:19",{"source":7,"skillName":5,"commands":35,"prompt":45,"zipAvailable":46},[36,39,42],{"tool":37,"command":38},"npx","npx skills add ComeOnOliver\u002Fskillshub --skill openai-sdk",{"tool":40,"command":41},"bunx","bunx skills add ComeOnOliver\u002Fskillshub --skill openai-sdk",{"tool":43,"command":44},"pnpm","pnpm dlx skills add ComeOnOliver\u002Fskillshub --skill openai-sdk","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002FTerminalSkills\u002Fskills\u002Fopenai-sdk\u002FSKILL.md",true,[],[49,63,73,81,87,94],{"skillNo":50,"name":51,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":7,"ownerLogin":8,"ownerAvatarUrl":9,"ownerAccountNo":10,"ownerDisplayName":11,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":52,"categories":53,"keywords":59,"publishedAt":21},"01M6FKJN13GMG4KY57J3QD8GY5","model-hierarchy-skill","https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Fzscole\u002Fmodel-hierarchy-skill\u002Fmodel-hierarchy-skill\u002FSKILL.md",[54],{"categoryNo":55,"categoryName":56,"taxonomyType":57,"taxonomyTypeDesc":58},"01JBSEEDCAT000000000000023","Skill与智能体开发","SCENARIO","使用场景",[60,61,62],"model","model hierarchy","model hierarchy skill",{"skillNo":64,"name":65,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":7,"ownerLogin":8,"ownerAvatarUrl":9,"ownerAccountNo":10,"ownerDisplayName":11,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":66,"categories":67,"keywords":69,"publishedAt":21},"01M6FKJJJ6GCAMR4PPPRD12M5X","zoom-mcp","https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Fzoom\u002Fskills\u002Fzoom-mcp\u002FSKILL.md",[68],{"categoryNo":55,"categoryName":56,"taxonomyType":57,"taxonomyTypeDesc":58},[70,71,72],"MCP","zoom","zoom mcp",{"skillNo":74,"name":75,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":7,"ownerLogin":8,"ownerAvatarUrl":9,"ownerAccountNo":10,"ownerDisplayName":11,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":76,"categories":77,"keywords":78,"publishedAt":21},"01M6FKJE3KYT3KPEZMEEHYKA6K","zoom-apps-sdk","https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Fzoom\u002Fskills\u002Fzoom-apps-sdk\u002FSKILL.md",[],[18,79,80,71],"zoom apps sdk","apps",{"skillNo":82,"name":83,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":7,"ownerLogin":8,"ownerAvatarUrl":9,"ownerAccountNo":10,"ownerDisplayName":11,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":84,"categories":85,"keywords":86,"publishedAt":21},"01M6FKJ9EDH9Q5VWDF8HAJRSP0","windows","https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Fzoom\u002Fskills\u002Fwindows\u002FSKILL.md",[],[83],{"skillNo":88,"name":89,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":7,"ownerLogin":8,"ownerAvatarUrl":9,"ownerAccountNo":10,"ownerDisplayName":11,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":90,"categories":91,"keywords":93,"publishedAt":21},"01M6FKJ666BEEFC3AE9GJ72Q93","whiteboard","https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Fzoom\u002Fskills\u002Fwhiteboard\u002FSKILL.md",[92],{"categoryNo":55,"categoryName":56,"taxonomyType":57,"taxonomyTypeDesc":58},[89],{"skillNo":95,"name":96,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":7,"ownerLogin":8,"ownerAvatarUrl":9,"ownerAccountNo":10,"ownerDisplayName":11,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":97,"categories":98,"keywords":99,"publishedAt":21},"01M6FKJ21WFCDGTJQ2Q91T9DVW","websockets","https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Fzoom\u002Fskills\u002Fwebsockets\u002FSKILL.md",[],[96]]