openai-api-development
Skill275 starsChanged 52 days agoApache-2.0View on GitHub
Expert guidance for OpenAI API development including GPT models, Assistants API, function calling, embeddings, and best practices for production applications.
- Reads credentials
In this repository264 other files it gives its agents.
- accessibility-a11ySkill
- alpine-jsSkill
- analytics-data-analysisSkill
- android-developmentSkill
- angular-developmentSkill
- angularSkill
- anime-jsSkill
- anthropic-claude-developmentSkill
- api-developmentSkill
- apollo-graphqlSkill
- aspnet-coreSkill
- astroSkill
- auth0-authenticationSkill
- autogen-developmentSkill
- automl-hyperparameter-optimizationSkill
- aws-developmentSkill
- azureSkill
- backend-developmentSkill
- bash-scriptingSkill
- beautifulsoup-parsingSkill
- bitbucket-workflowSkill
- blazorSkill
- blender-python-addonSkill
- blockchainSkill
- bootstrapSkill
- business-central-developmentSkill
- cheerio-parsingSkill
- chrome-extension-developmentSkill
- ci-cd-best-practicesSkill
- clean-architectureSkill
- clean-codeSkill
- clerk-authenticationSkill
- cloudflare-developmentSkill
- computer-vision-opencvSkill
- convexSkill
- cppSkill
- c-sharpSkill
- cssSkill
- cypressSkill
- data-analysis-jupyterSkill
- data-analystSkill
- data-jupyter-pythonSkill
- deep-learning-pythonSkill
- deep-learning-pytorchSkill
- deep-learningSkill
- deno-typescriptSkill
- design-systemsSkill
- devopsSkill
- django-pythonSkill
- django-rest-api-developmentSkill
- dockerSkill
- dotnetSkill
- drizzle-ormSkill
- drupal-developmentSkill
- elasticsearch-best-practicesSkill
- electron-developmentSkill
- elixirSkill
- embedded-stm32Skill
- esbuild-bundlerSkill
- ethereumSkill
- The first 60 shown.
The file
Show its rules and text
We split this skill into the rules it gives an agent
17 rules. About 0 are common, 10 are distinctive, and 7 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈10
Distinctive · estimate
This author's own choices. Worth a look.
7
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 15
Write concise, technical responses with accurate Python examples
- Distinctive: line 16
Use type hints for all function signatures
- Distinctive: line 18
Never hardcode API keys; use environment variables
- Distinctive: line 19
Follow OpenAI's usage policies and rate limit guidelines
- Very specific: line 36
Use python-dotenv for local development
- Very specific: line 78
Use gpt-4o for complex reasoning and multimodal tasks
- Very specific: line 79
Use gpt-4o-mini for faster, cost-effective responses
- Very specific: line 80
Use o1 models for advanced reasoning tasks
- Very specific: line 81
Consider gpt-3.5-turbo for simple tasks requiring speed
- Very specific: line 211
Use text-embedding-3-small for cost-effective solutions
- Very specific: line 212
Use text-embedding-3-large for maximum accuracy
- Distinctive: line 215
Use appropriate dimensions parameter for storage optimization
- Distinctive: line 273
Use appropriate models for task complexity
- Distinctive: line 275
Use streaming for long responses
- Distinctive: line 278
Use batch API for non-time-sensitive requests
- Distinctive: line 282
Never expose API keys in client-side code
- Distinctive: line 285
Use content moderation for user-generated content
≈ “Common” is an estimate: at least 1 in 5 of the 383,637 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
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
.envfiles, never commit them - Use
python-dotenvfor 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.contentStreaming 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-4ofor complex reasoning and multimodal tasks - Use
gpt-4o-minifor faster, cost-effective responses - Use
o1models for advanced reasoning tasks - Consider
gpt-3.5-turbofor 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 responseAssistants 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].embeddingBest Practices for Embeddings
- Use
text-embedding-3-smallfor cost-effective solutions - Use
text-embedding-3-largefor 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 backoffAPIError: Check API status, retry with backoffAuthenticationError: Verify API keyInvalidRequestError: 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_tokenslimits - 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)
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

