OpenAI API Guide
OpenAI provides two main APIs: Chat Completions API (classic) and Responses API (newer, recommended for agent scenarios).
Installation
- Python
- JavaScript
- curl
pip install openai
npm install openai
# curl is usually available on the system; no SDK installation is required
Get an API Key
Go to AI Supermarket and create an API Key.
Chat Completions API (Streaming)
Note: this platform's Chat Completions API only supports streaming calls (
stream=True).
- Python
- JavaScript
- curl
from openai import OpenAI
client = OpenAI(api_key="your-api-key", base_url="https://aisupermarket.work/v1")
stream = client.chat.completions.create(
model="gpt-5.4",
messages=[{"role": "user", "content": "Hello, please introduce yourself"}],
stream=True,
)
for chunk in stream:
if chunk.choices[0].delta.content is not None:
print(chunk.choices[0].delta.content, end="", flush=True)
import OpenAI from "openai";
const client = new OpenAI({
apiKey: "your-api-key",
baseURL: "https://aisupermarket.work/v1",
});
const stream = await client.chat.completions.create({
model: "gpt-5.4",
messages: [{ role: "user", content: "Hello, please introduce yourself" }],
stream: true,
});
for await (const chunk of stream) {
const content = chunk.choices[0]?.delta?.content;
if (content) process.stdout.write(content);
}
curl https://aisupermarket.work/v1/chat/completions \
-H "Authorization: Bearer your-api-key" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-5.4",
"messages": [{"role": "user", "content": "Hello, please introduce yourself"}],
"stream": true
}'
Responses API (Newer)
The Responses API is OpenAI's recommended API for building agents and supports built-in tools such as web search.
- Python
- JavaScript
- curl
from openai import OpenAI
client = OpenAI(api_key="your-api-key", base_url="https://aisupermarket.work/v1")
response = client.responses.create(
model="gpt-5.4",
input="Hello, please introduce yourself"
)
print(response.output_text)
import OpenAI from "openai";
const client = new OpenAI({
apiKey: "your-api-key",
baseURL: "https://aisupermarket.work/v1",
});
const response = await client.responses.create({
model: "gpt-5.4",
input: "Hello, please introduce yourself",
});
console.log(response.output_text);
curl https://aisupermarket.work/v1/responses \
-H "Authorization: Bearer your-api-key" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-5.4",
"input": "Hello, please introduce yourself"
}'
Common Models
| Model | Description |
|---|---|
gpt-5.4 | Flagship model with strong capabilities |
gpt-5.4-mini | Lightweight model with lower latency and cost |
gpt-image-2 | Image generation model |