スキル一覧に戻る
timequity

openai-sdk

by timequity

Describe your idea, get a deployed product. All Craft Coder skills + brainstorming, validation, and deployment automation.

0🍴 0📅 2026年1月3日
GitHubで見るManusで実行

SKILL.md


name: openai-sdk description: | OpenAI official SDK usage (Python, Node.js). Use when: writing code that calls OpenAI API, implementing chat/embeddings/images/audio features, handling streaming responses, async patterns, error handling with SDK. For raw HTTP/REST calls, see openai-api skill.

OpenAI SDK

Official SDKs for Python and Node.js. Handles auth, retries, types automatically.

Quick Start

Python

pip install openai
from openai import OpenAI

client = OpenAI()  # Uses OPENAI_API_KEY env var

response = client.chat.completions.create(
    model="gpt-4o",
    messages=[{"role": "user", "content": "Hello!"}]
)
print(response.choices[0].message.content)

Node.js

npm install openai
import OpenAI from "openai";

const client = new OpenAI();  // Uses OPENAI_API_KEY env var

const response = await client.chat.completions.create({
  model: "gpt-4o",
  messages: [{ role: "user", content: "Hello!" }],
});
console.log(response.choices[0].message.content);

Environment Variables

export OPENAI_API_KEY="sk-..."
export OPENAI_ORG_ID="org-..."      # Optional
export OPENAI_PROJECT_ID="proj-..." # Optional

Key Features

FeaturePythonNode.js
Sync clientOpenAI()new OpenAI()
Async clientAsyncOpenAI()Same (async/await)
Streamingstream=Truestream: true
Auto-retryBuilt-inBuilt-in
Timeouttimeout=60timeout: 60000
TypesFull typingTypeScript

Common Operations

Chat Completion

response = client.chat.completions.create(
    model="gpt-4o",
    messages=[{"role": "user", "content": "Hi"}]
)

Streaming

stream = client.chat.completions.create(
    model="gpt-4o",
    messages=[{"role": "user", "content": "Hi"}],
    stream=True
)
for chunk in stream:
    print(chunk.choices[0].delta.content or "", end="")

Embeddings

response = client.embeddings.create(
    model="text-embedding-3-small",
    input="Hello world"
)
vector = response.data[0].embedding

Image Generation

response = client.images.generate(
    model="dall-e-3",
    prompt="A sunset over mountains",
    size="1024x1024"
)
url = response.data[0].url

Audio Transcription

with open("audio.mp3", "rb") as f:
    transcript = client.audio.transcriptions.create(
        model="whisper-1",
        file=f
    )
print(transcript.text)

Error Handling

from openai import OpenAI, APIError, RateLimitError

client = OpenAI()

try:
    response = client.chat.completions.create(...)
except RateLimitError:
    # Retry with backoff
except APIError as e:
    print(f"API error: {e.status_code}")

References

  • openai-api skill — Raw REST API without SDK

スコア

総合スコア

70/100

リポジトリの品質指標に基づく評価

SKILL.md

SKILL.mdファイルが含まれている

+20
LICENSE

ライセンスが設定されている

+10
説明文

100文字以上の説明がある

+10
人気

GitHub Stars 100以上

0/15
最近の活動

3ヶ月以内に更新がある

0/10
フォーク

10回以上フォークされている

0/5
Issue管理

オープンIssueが50未満

+5
言語

プログラミング言語が設定されている

+5
タグ

1つ以上のタグが設定されている

0/5

レビュー

💬

レビュー機能は近日公開予定です