Text generation
import openai
client = openai.OpenAI(
base_url="https://api.llm7.io/v1",
api_key="unused", # Use a https://dash.llm7.io/ token for higher limits.
)
resp = client.chat.completions.create(
model="default", # or "fast", "pro", or a model ID from /v1/models
messages=[
{"role": "system", "content": "Answer concisely."},
{"role": "user", "content": "Give me three onboarding tips for new engineers."},
],
temperature=0.4,
)
print(resp.choices[0].message.content)
Use
model="fast" for lowest latency and model="pro" for higher-quality paid models. See Available models for selectors and Models API for live model details.Image generation
import base64
import os
from openai import OpenAI
client = OpenAI(
base_url="https://api.llm7.io/v1",
api_key=os.environ["LLM7_API_TOKEN"],
)
result = client.images.generate(
model="gpt-image-2",
prompt="A clean product photo of a matte black desk lamp on a white desk",
size="1024x1024",
n=1,
)
image_bytes = base64.b64decode(result.data[0].b64_json)
with open("generated.png", "wb") as file:
file.write(image_bytes)
See Image generation and edits for edit examples, strict field validation, and normalized response details.
