Skip to content
NEW GPT-5.5 / Claude 4.6 is now live — try it today →
Guides Cookbooks 5 min read

Python Batch Calls

from openai import OpenAI
from concurrent.futures import ThreadPoolExecutor

client = OpenAI(api_key="sk-...", base_url="https://api.onefast.ai/v1")

def ask(text): r = client.chat.completions.create( model="gpt-4o-mini", messages=[{"role": "user", "content": text}], max_tokens=100, ) return r.choices[0].message.content

with ThreadPoolExecutor(max_workers=8) as ex: results = list(ex.map(ask, ["Hello"] * 32))

> Mind each model’s RPM limits; use exponential backoff when you hit 429.