Giotto exposes an OpenAI-compatible /v1 endpoint. Use the standard openai Python package with a Giotto base URL and a Giotto API credential. This page covers the routes and patterns used in these guides.
For general client installation and API syntax, see the official OpenAI Python quickstart. Giotto-specific availability and limits are described below.
Install and configure
python3 -m pip install openai export GIOTTO_OPENAI_BASE_URL="https://cloud.giotto.ai/v1" export GIOTTO_API_KEY="<YOUR_CLIENT_ID>:<YOUR_CLIENT_SECRET>"
Use a Giotto client ID and client secret from API & Plans → API Keys. The entire CLIENT_ID:CLIENT_SECRET string is the OpenAI client's api_key value for Giotto. It is sent as an HTTP bearer token. Store it in a secrets manager or server-side environment variables.
import os
from openai import OpenAI
client = OpenAI(
base_url=os.environ["GIOTTO_OPENAI_BASE_URL"],
api_key=os.environ["GIOTTO_API_KEY"],
)List and select models
for model in client.models.list().data:
print(model.id)The list reflects models available through the gateway to your credential. Use a returned ID in your request. A model may still have feature-specific limitations, so test the operations your application needs.
Chat Completions
This is the main generation path documented for Giotto. Send a messages array and read the first returned choice:
completion = client.chat.completions.create(
model="giotto-alto",
messages=[
{"role": "system", "content": "Answer concisely."},
{"role": "user", "content": "What is a Python context manager?"},
],
)
print(completion.choices[0].message.content)giotto-alto is an example model ID. Use a model returned for your credential; availability can differ by deployment and account.
Stream text
stream = client.chat.completions.create(
model="giotto-alto",
messages=[{"role": "user", "content": "Write a short welcome message."}],
stream=True,
)
for chunk in stream:
if chunk.choices:
print(chunk.choices[0].delta.content or "", end="", flush=True)
print()The gateway forwards server-sent events from the model backend. Some chunks may have no text; tool-call deltas require separate handling. Close a stream you stop consuming so its concurrency slot can be released.
Async client
Use AsyncOpenAI when your application uses asyncio:
import asyncio
import os
from openai import AsyncOpenAI
async def main() -> None:
async with AsyncOpenAI(
base_url=os.environ["GIOTTO_OPENAI_BASE_URL"],
api_key=os.environ["GIOTTO_API_KEY"],
) as client:
completion = await client.chat.completions.create(
model="giotto-alto",
messages=[{"role": "user", "content": "Explain async I/O briefly."}],
)
print(completion.choices[0].message.content)
asyncio.run(main())Responses API
The gateway forwards POST /v1/responses to the selected model backend. If your deployment supports the requested Responses features, the standard client can call it:
response = client.responses.create(
model="giotto-alto",
input="Explain what an API is in two sentences.",
)
print(response.output_text)Backend support for Responses parameters, streaming events, and response fields varies. Confirm this route with your deployed model before building on it. The old Giotto SDK's poll=False, responses.wait(), and orchestration-event stream are not OpenAI client features and are not part of this endpoint's documented contract.
Errors and response headers
Non-successful HTTP responses raise exceptions from the OpenAI Python client. An APIStatusError exposes the HTTP status and response headers, including Retry-After when Giotto supplies it:
from openai import APIConnectionError, APIStatusError, APITimeoutError
try:
completion = client.chat.completions.create(
model="giotto-alto",
messages=[{"role": "user", "content": "Hello"}],
)
except APIStatusError as exc:
print(exc.status_code)
print(exc.response.headers.get("retry-after"))
print(exc.response.text)
except (APIConnectionError, APITimeoutError) as exc:
print(f"Connection or timeout error: {exc}")Check the status and error.code in the body before retrying. A 429 may mean a per-minute or concurrency limit; a 402 means insufficient by-token credits. The client may retry some errors automatically, so set an application deadline and avoid blindly resending a request when the outcome is uncertain. See API errors, rate limits, and retries.
Feature boundaries
- The gateway supports model listing and routes Chat Completions requests by model ID.
- Chat Completions text streaming is forwarded from the selected model backend.
- Tool calls depend on the selected model and its deployment.
- Other
/v1routes are forwarded, but full OpenAI API feature parity is not guaranteed. - Image input, hosted tools, background jobs, and other optional features require separate validation with the selected model and route.