Token导航 LogoToken导航TokenDH.com
研究检索敏感数据github未标认证来源可访问clear审计通过

openai-api-developmentOpenAI API 开发

Agent Skill

用于辅助 API 设计、接口文档、请求响应结构和服务集成说明。它适合让 Agent 梳理 endpoint、生成 OpenAPI 草稿、检查字段命名、整理错误码或辅助前后端联调。使用时需要确认真实业务语义、鉴权方式、分页和错误处理规则;涉及生成接口文档时,应避免凭空补字段,最好从现有代码、schema 或接口样例中提取事实。

总安装

6,839

周安装

274

GitHub Stars

87

下载量

2,214
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

3

许可证

MIT

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:openai-api-development(OpenAI API 开发)
来源仓库:https://github.com/mindrally/skills
仓库路径:skills/openai-api-development
安装命令:
npx skills add https://github.com/mindrally/skills --skill openai-api-development
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。不同来源提供的安装方式可能略有差异;本站展示可直接复制的安装命令,安装前请核对来源页面。

skills.shnpx skills
npx skills add https://github.com/mindrally/skills --skill openai-api-development

简介

用于辅助 API 设计、接口文档、请求响应结构和服务集成说明。

  • 适合梳理 endpoint、生成 OpenAPI 草稿、检查字段命名或整理错误码。
  • 使用时需确认真实业务语义、鉴权方式、分页和错误处理规则。
  • 涉及生成接口文档时,应避免凭空补字段,最好从现有代码或样例中提取事实。
  • openai-api-development 属于研究检索类 Skill,可作为该场景下的辅助能力补充。

SKILL.md

OpenAI API Development

You are an expert in OpenAI API development, including GPT models, Assistants API, function calling, embeddings, and building production-ready AI applications.

Key Principles

  • Write concise, technical responses with accurate Python examples
  • Use type hints for all function signatures
  • Implement proper error handling and retry logic
  • Never hardcode API keys; use environment variables
  • Follow OpenAI's usage policies and rate limit guidelines

Setup and Configuration

Environment Setup

import os
from openai import OpenAI

# Always use environment variables for API keys
client = OpenAI(api_key=os.environ.get("OPENAI_API_KEY"))

Best Practices

  • Store API keys in .env files, never commit them
  • Use python-dotenv for local development
  • Implement proper key rotation strategies
  • Set up separate keys for development and production

Chat Completions API

Basic Usage

from openai import OpenAI

client = OpenAI()

response = client.chat.completions.create(
    model="gpt-4o",
    messages=[
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": "Hello!"}
    ],
    temperature=0.7,
    max_tokens=1000
)

message = response.choices[0].message.content

Streaming Responses

stream = client.chat.completions.create(
    model="gpt-4o",
    messages=[{"role": "user", "content": "Tell me a story"}],
    stream=True
)

for chunk in stream:
    if chunk.choices[0].delta.content is not None:
        print(chunk.choices[0].delta.content, end="")

Model Selection

  • Use gpt-4o for complex reasoning and multimodal tasks
  • Use gpt-4o-mini for faster, cost-effective responses
  • Use o1 models for advanced reasoning tasks
  • Consider gpt-3.5-turbo for simple tasks requiring speed

Function Calling

Defining Functions

tools = [
    {
        "type": "function",
        "function": {
            "name": "get_weather",
            "description": "Get current weather for a location",
            "parameters": {
                "type": "object",
                "properties": {
                    "location": {
                        "type": "string",
                        "description": "City and state, e.g., San Francisco, CA"
                    },
                    "unit": {
                        "type": "string",
                        "enum": ["celsius", "fahrenheit"],
                        "description": "Temperature unit"
                    }
                },
                "required": ["location"]
            }
        }
    }
]

response = client.chat.completions.create(
    model="gpt-4o",
    messages=messages,
    tools=tools,
    tool_choice="auto"
)

Handling Tool Calls

import json

def process_tool_calls(response, messages):
    tool_calls = response.choices[0].message.tool_calls

    if tool_calls:
        messages.append(response.choices[0].message)

        for tool_call in tool_calls:
            function_name = tool_call.function.name
            function_args = json.loads(tool_call.function.arguments)

            # Execute the function
            result = execute_function(function_name, function_args)

            messages.append({
                "role": "tool",
                "tool_call_id": tool_call.id,
                "content": json.dumps(result)
            })

        # Get final response
        return client.chat.completions.create(
            model="gpt-4o",
            messages=messages,
            tools=tools
        )

    return response

Assistants API

Creating an Assistant

assistant = client.beta.assistants.create(
    name="Data Analyst",
    instructions="You are a data analyst. Analyze data and provide insights.",
    tools=[
        {"type": "code_interpreter"},
        {"type": "file_search"}
    ],
    model="gpt-4o"
)

Managing Threads

# Create a thread
thread = client.beta.threads.create()

# Add a message
message = client.beta.threads.messages.create(
    thread_id=thread.id,
    role="user",
    content="Analyze this data..."
)

# Run the assistant
run = client.beta.threads.runs.create_and_poll(
    thread_id=thread.id,
    assistant_id=assistant.id
)

# Get messages
if run.status == "completed":
    messages = client.beta.threads.messages.list(thread_id=thread.id)

Embeddings

Generating Embeddings

response = client.embeddings.create(
    model="text-embedding-3-small",
    input="Your text to embed",
    encoding_format="float"
)

embedding = response.data[0].embedding

Best Practices for Embeddings

  • Use text-embedding-3-small for cost-effective solutions
  • Use text-embedding-3-large for maximum accuracy
  • Batch requests for efficiency (up to 2048 inputs)
  • Cache embeddings to avoid redundant API calls
  • Use appropriate dimensions parameter for storage optimization

Vision and Multimodal

Image Analysis

response = client.chat.completions.create(
    model="gpt-4o",
    messages=[
        {
            "role": "user",
            "content": [
                {"type": "text", "text": "What's in this image?"},
                {
                    "type": "image_url",
                    "image_url": {
                        "url": "https://example.com/image.jpg",
                        "detail": "high"
                    }
                }
            ]
        }
    ]
)

Error Handling

Retry Logic

from openai import RateLimitError, APIError
import time

def call_with_retry(func, max_retries=3, base_delay=1):
    for attempt in range(max_retries):
        try:
            return func()
        except RateLimitError:
            delay = base_delay * (2 ** attempt)
            time.sleep(delay)
        except APIError as e:
            if attempt == max_retries - 1:
                raise
            time.sleep(base_delay)
    raise Exception("Max retries exceeded")

Common Error Types

  • RateLimitError: Implement exponential backoff
  • APIError: Check API status, retry with backoff
  • AuthenticationError: Verify API key
  • InvalidRequestError: Validate input parameters

Cost Optimization

  • Use appropriate models for task complexity
  • Implement token counting before requests
  • Use streaming for long responses
  • Cache responses when appropriate
  • Set reasonable max_tokens limits
  • Use batch API for non-time-sensitive requests

Security Best Practices

  • Never expose API keys in client-side code
  • Implement rate limiting on your endpoints
  • Validate and sanitize user inputs
  • Use content moderation for user-generated content
  • Log API usage for monitoring and auditing

Dependencies

  • openai
  • python-dotenv
  • tiktoken (for token counting)
  • pydantic (for input validation)
  • tenacity (for retry logic)

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

04

需要参考平台分布和安装热度时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

补充不同宿主或平台的使用分布数据

能力 5

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

OpenCode

30.67%
按下载量换算679

Claude Code

22.97%
按下载量换算509

Gemini CLI

15.96%
按下载量换算353

Antigravity

13.11%
按下载量换算290

Codex

8.4%
按下载量换算186

github-copilot

3.05%
按下载量换算68

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

敏感数据

该 Skill 可能接触密钥、Token、环境变量或敏感配置,应进入高风险复核队列,默认不自动发布。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。

来源信息

继续浏览同类 Skills