Skip to main content

OpenAI API Guide

OpenAI provides two main APIs: Chat Completions API (classic) and Responses API (newer, recommended for agent scenarios).

Installation

pip install openai

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).

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)

Responses API (Newer)

The Responses API is OpenAI's recommended API for building agents and supports built-in tools such as web search.

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)

Common Models

ModelDescription
gpt-5.4Flagship model with strong capabilities
gpt-5.4-miniLightweight model with lower latency and cost
gpt-image-2Image generation model