Python examples
When to use this page
Use this page for Python services, scripts, notebooks, or agents.
Install
pip install openai
Create a response
import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ["QUOTAFLOW_API_KEY"],
base_url="https://api.quotaflow.ai/openai/v1",
)
response = client.responses.create(
model="gpt-5.5",
input="Return only: connected",
stream=False,
)
print(response)
Chat completions compatibility
import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ["QUOTAFLOW_API_KEY"],
base_url="https://api.quotaflow.ai/openai/v1",
)
completion = client.chat.completions.create(
model="gpt-5.5",
messages=[{"role": "user", "content": "Return only: ready"}],
)
print(completion.choices[0].message.content)
Kimi JSON mode chat
Use kimi-k2.7-code on /chat/completions when you need a Chat Completions-shaped coding model with streaming or strict JSON output. GLM glm-5.2 supports non-streaming messages and non-streaming tools; stream: true currently fails closed with 503 pending verified availability evidence, while strict JSON mode returns 400 invalid_request_error.
import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ["QUOTAFLOW_API_KEY"],
base_url="https://api.quotaflow.ai/openai/v1",
)
kimi_json = client.chat.completions.create(
model="kimi-k2.7-code",
messages=[{"role": "user", "content": "Return JSON with status connected."}],
response_format={"type": "json_object"},
stream=False,
)
print(kimi_json.choices[0].message.content)
Embeddings
import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ["QUOTAFLOW_API_KEY"],
base_url="https://api.quotaflow.ai/openai/v1",
)
embedding = client.embeddings.create(
model="text-embedding-3-small",
input="Quotaflow embeddings are connected.",
)
print(len(embedding.data[0].embedding))
Anthropic-compatible Messages
Use requests when you want to keep the Anthropic Messages request shape.
import os
import requests
response = requests.post(
"https://api.quotaflow.ai/v1/messages",
headers={
"x-api-key": os.environ["QUOTAFLOW_API_KEY"],
"anthropic-version": "2023-06-01",
"Content-Type": "application/json",
},
json={
"model": "claude-sonnet-4-6",
"max_tokens": 128,
"messages": [{"role": "user", "content": "Return only: connected"}],
},
timeout=60,
)
response.raise_for_status()
print(response.json())
Image generation
import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ["QUOTAFLOW_API_KEY"],
base_url="https://api.quotaflow.ai/openai/v1",
)
image = client.images.generate(
model="gpt-image-2",
prompt="A clean teal API dashboard illustration.",
size="1024x1024",
response_format="b64_json",
)
print(image.data[0].b64_json[:24])
Set response_format to url for non-streaming image generation when you want a temporary hosted URL instead of inline base64. Image edits are not part of the active V3 contract.
Video generation
Use requests for task-based video generation when your SDK version does not expose a video helper yet.
import os
import requests
headers = {
"Authorization": f"Bearer {os.environ['QUOTAFLOW_API_KEY']}",
"Content-Type": "application/json",
}
create_response = requests.post(
"https://api.quotaflow.ai/openai/v1/videos",
headers=headers,
json={
"model": "seedance-2.0-fast",
"prompt": "A cinematic drone shot over a coastal city at sunrise.",
"durationSeconds": 4,
"resolution": "1080p",
"aspectRatio": "16:9",
},
timeout=60,
)
create_response.raise_for_status()
task = create_response.json()
print(task)
task_id = task.get("id") or task.get("task_id")
result_response = requests.get(
f"https://api.quotaflow.ai/openai/v1/videos/{task_id}",
headers={"Authorization": f"Bearer {os.environ['QUOTAFLOW_API_KEY']}"},
timeout=60,
)
result_response.raise_for_status()
print(result_response.json())