Loading...
Loading...
OpenAI API via curl. Use this skill for GPT chat completions, DALL-E image generation, Whisper audio transcription, embeddings, and text-to-speech.
npx skill4agent add vm0-ai/vm0-skills openaicurlOfficial docs:https://platform.openai.com/docs/api-reference
export OPENAI_API_KEY="sk-..."| Model | Input (per 1M tokens) | Output (per 1M tokens) |
|---|---|---|
| GPT-4o | $2.50 | $10.00 |
| GPT-4o-mini | $0.15 | $0.60 |
| GPT-4 Turbo | $10.00 | $30.00 |
| text-embedding-3-small | $0.02 | - |
| text-embedding-3-large | $0.13 | - |
Important: When usingin a command that pipes to another command, wrap the command containing$VARin$VAR. Due to a Claude Code bug, environment variables are silently cleared when pipes are used directly.bash -c '...'bashbash -c 'curl -s "https://api.example.com" -H "Authorization: Bearer $API_KEY"' | jq .
OPENAI_API_KEYhttps://api.openai.com/v1/tmp/openai_request.json{
"model": "gpt-4o-mini",
"messages": [{"role": "user", "content": "Hello, who are you?"}]
}bash -c 'curl -s "https://api.openai.com/v1/chat/completions" -H "Content-Type: application/json" -H "Authorization: Bearer ${OPENAI_API_KEY}" -d @/tmp/openai_request.json' | jq '.choices[0].message.content'gpt-4ogpt-4o-minigpt-4-turbogpt-3.5-turboo1o1-mini/tmp/openai_request.json{
"model": "gpt-4o-mini",
"messages": [
{"role": "system", "content": "You are a helpful assistant that responds in JSON format."},
{"role": "user", "content": "List 3 programming languages with their main use cases."}
]
}bash -c 'curl -s "https://api.openai.com/v1/chat/completions" -H "Content-Type: application/json" -H "Authorization: Bearer ${OPENAI_API_KEY}" -d @/tmp/openai_request.json' | jq '.choices[0].message.content'/tmp/openai_request.json{
"model": "gpt-4o-mini",
"messages": [{"role": "user", "content": "Write a haiku about programming."}],
"stream": true
}curl -s "https://api.openai.com/v1/chat/completions" -H "Content-Type: application/json" -H "Authorization: Bearer ${OPENAI_API_KEY}" -d @/tmp/openai_request.json/tmp/openai_request.json{
"model": "gpt-4o-mini",
"messages": [
{"role": "system", "content": "Return JSON only."},
{"role": "user", "content": "Give me info about Paris: name, country, population."}
],
"response_format": {"type": "json_object"}
}bash -c 'curl -s "https://api.openai.com/v1/chat/completions" -H "Content-Type: application/json" -H "Authorization: Bearer ${OPENAI_API_KEY}" -d @/tmp/openai_request.json' | jq '.choices[0].message.content'/tmp/openai_request.json{
"model": "gpt-4o-mini",
"messages": [
{
"role": "user",
"content": [
{"type": "text", "text": "What is in this image?"},
{"type": "image_url", "image_url": {"url": "https://upload.wikimedia.org/wikipedia/commons/thumb/3/3a/Cat03.jpg/1200px-Cat03.jpg"}}
]
}
],
"max_tokens": 300
}bash -c 'curl -s "https://api.openai.com/v1/chat/completions" -H "Content-Type: application/json" -H "Authorization: Bearer ${OPENAI_API_KEY}" -d @/tmp/openai_request.json' | jq '.choices[0].message.content'/tmp/openai_request.json{
"model": "gpt-4o-mini",
"messages": [{"role": "user", "content": "What is the weather in Tokyo?"}],
"tools": [
{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get current weather for a location",
"parameters": {
"type": "object",
"properties": {
"location": {"type": "string", "description": "City name"}
},
"required": ["location"]
}
}
}
]
}bash -c 'curl -s "https://api.openai.com/v1/chat/completions" -H "Content-Type: application/json" -H "Authorization: Bearer ${OPENAI_API_KEY}" -d @/tmp/openai_request.json' | jq '.choices[0].message.tool_calls'/tmp/openai_request.json{
"model": "text-embedding-3-small",
"input": "The quick brown fox jumps over the lazy dog."
}bash -c 'curl -s "https://api.openai.com/v1/embeddings" -H "Content-Type: application/json" -H "Authorization: Bearer ${OPENAI_API_KEY}" -d @/tmp/openai_request.json' | jq '.data[0].embedding[:5]'text-embedding-3-smalltext-embedding-3-large/tmp/openai_request.json{
"model": "dall-e-3",
"prompt": "A white cat sitting on a windowsill, digital art",
"n": 1,
"size": "1024x1024"
}bash -c 'curl -s "https://api.openai.com/v1/images/generations" -H "Content-Type: application/json" -H "Authorization: Bearer ${OPENAI_API_KEY}" -d @/tmp/openai_request.json' | jq '.data[0].url'size1024x10241792x10241024x1792qualitystandardhdstylevividnaturalbash -c 'curl -s "https://api.openai.com/v1/audio/transcriptions" -H "Authorization: Bearer ${OPENAI_API_KEY}" -F "file=@audio.mp3" -F "model=whisper-1"' | jq '.text'/tmp/openai_request.json{
"model": "tts-1",
"input": "Hello! This is a test of OpenAI text to speech.",
"voice": "alloy"
}curl -s "https://api.openai.com/v1/audio/speech" -H "Content-Type: application/json" -H "Authorization: Bearer ${OPENAI_API_KEY}" -d @/tmp/openai_request.json --output speech.mp3alloyechofableonyxnovashimmertts-1tts-1-hdbash -c 'curl -s "https://api.openai.com/v1/models" -H "Authorization: Bearer ${OPENAI_API_KEY}"' | jq -r '.data[].id' | sort | head -20/tmp/openai_request.json{
"model": "gpt-4o-mini",
"messages": [{"role": "user", "content": "Hi!"}]
}bash -c 'curl -s "https://api.openai.com/v1/chat/completions" -H "Content-Type: application/json" -H "Authorization: Bearer ${OPENAI_API_KEY}" -d @/tmp/openai_request.json' | jq '.usage'prompt_tokenscompletion_tokenstotal_tokensgpt-4o-minigpt-4oo1response_formatgpt-4ogpt-4o-mini