Skip to main content

Your local setup

Make your first API request with Python

Use the standard OpenAI Python client to send a request to Giotto's OpenAI-compatible endpoint. This guide uses Chat Completions as its starting point.Before you beginYou need a Giotto account with API access, a client ID and client secr...

Use the standard OpenAI Python client to send a request to Giotto's OpenAI-compatible endpoint. This guide uses Chat Completions as its starting point.

Before you begin

You need a Giotto account with API access, a client ID and client secret from API & Plans → API Keys, a positive balance if using by-token credits, and a Python environment where you can install packages.

Step 1: Install the OpenAI Python package

python3 -m pip install openai

No Giotto-specific package index is required.

Step 2: Configure the Giotto endpoint and credential

In your terminal, set these environment variables with your own values:

export GIOTTO_OPENAI_BASE_URL="https://cloud.giotto.ai/v1"
export GIOTTO_API_KEY="<YOUR_CLIENT_ID>:<YOUR_CLIENT_SECRET>"

The colon between the client ID and client secret is part of the credential format. The OpenAI client sends this value as a bearer token. Keep it on your server or in a secrets manager; never put it in browser code or source control.

Step 3: Create a Python file

Save this as quickstart.py:

import os

from openai import OpenAI


client = OpenAI(
    base_url=os.environ["GIOTTO_OPENAI_BASE_URL"],
    api_key=os.environ["GIOTTO_API_KEY"],
)

models = client.models.list()
model_id = models.data[0].id

completion = client.chat.completions.create(
    model=model_id,
    messages=[
        {"role": "user", "content": "Explain what an API is in two sentences."}
    ],
)

print(completion.choices[0].message.content)

This example selects the first model returned for your credential. In an application, choose a specific model ID after reviewing the available models and its behavior.

Step 4: Run the request

python3 quickstart.py

A successful run prints generated text. The exact wording varies. If models.data is empty, ask your account administrator which models are enabled for the credential.

What the code does

  1. OpenAI(...) points the standard client at Giotto instead of the default OpenAI endpoint.
  2. client.models.list() retrieves model IDs available to your credential.
  3. client.chat.completions.create() sends a message to the chosen model.
  4. completion.choices[0].message.content reads the generated text.

Troubleshooting

Authentication fails

Check that GIOTTO_API_KEY contains the Giotto client ID, one colon, and the matching client secret. Confirm that your application uses the Giotto /v1 base URL and that the credential has not been rotated or disabled.

The model is unavailable

List models with client.models.list(), then use an ID returned for your credential. A model may be unavailable if it is not deployed, priced, or included in your API offering.

The balance is insufficient or a limit is reached

Check your API credits in Giotto. For HTTP 429, inspect Retry-After and reduce request volume. See API errors, rate limits, and retries.

Next steps

Powered by Zendesk