Skip to content

Google Colab

A Colab notebook is quick to share and quick to fill with real data. Call models from it through the gateway and every call is checked against your policies, charged to the right team and recorded in Request logs, with no provider key in the notebook.

What it is

Colab runs ordinary Python in Google's cloud, so you call the gateway with the SDK you already use: the OpenAI SDK, the Anthropic SDK or the Google GenAI SDK. The key lives in Colab's Secrets (the key icon in the left bar), never in a cell.

Colab's built-in AI assistant (Gemini in Colab) uses Google's own models and doesn't go through the gateway. Only the calls your code makes do.

The two settings

  1. In Secrets, add a secret named VIDAI_API_KEY with your Vidai key (starts vk_) as its value, and switch on Notebook access for this notebook.
  2. Read it in a cell and give the SDK the gateway's address:
SDK Base address Key
OpenAI (openai) https://<your-gateway>/v1 api_key=userdata.get("VIDAI_API_KEY")
Anthropic (anthropic) https://<your-gateway> api_key=userdata.get("VIDAI_API_KEY")
Google GenAI (google-genai) https://<your-gateway> in http_options api_key=userdata.get("VIDAI_API_KEY")

The gateway's address, and the base URL for each kind of client, are under Connect your app on the Keys page and in System › Settings › Gateway. You get the key from Keys › Issue a key; its secret is shown once. Use a provider's key nowhere.

A minimal call

from google.colab import userdata
from openai import OpenAI

client = OpenAI(base_url="https://<your-gateway>/v1", api_key=userdata.get("VIDAI_API_KEY"))
reply = client.chat.completions.create(
    model="gpt-4o-mini",
    messages=[{"role": "user", "content": "Reply with exactly: ok"}],
)
print(reply.choices[0].message.content)
!pip install -q anthropic
from google.colab import userdata
import anthropic

client = anthropic.Anthropic(base_url="https://<your-gateway>", api_key=userdata.get("VIDAI_API_KEY"))
reply = client.messages.create(
    model="claude-sonnet-4.5",
    max_tokens=50,
    messages=[{"role": "user", "content": "Reply with exactly: ok"}],
)
print(reply.content[0].text)
from google.colab import userdata
from google import genai
from google.genai import types

client = genai.Client(
    api_key=userdata.get("VIDAI_API_KEY"),
    http_options=types.HttpOptions(base_url="https://<your-gateway>"),
)
reply = client.models.generate_content(model="gemini-3.5-flash", contents="Reply with exactly: ok")
print(reply.text)

Any of the three reaches any provider: the OpenAI SDK can call claude-sonnet-4.5, the Anthropic SDK gpt-4o-mini, the Google GenAI SDK either. The gateway translates the request and the answer, so you keep the SDK you know. Install a package Colab doesn't have with !pip install -q ….

Streaming

Streaming works as in a script, and prints as it arrives in the cell's output. See OpenAI SDK for Python, Anthropic SDK for Python and Google GenAI SDK for Python.

Tool calls

Tools work on every provider the gateway translates to, as on each SDK's page. In Request logs, the Tool filter under More filters finds the calls that offered or called a tool by its name.

Reading what the gateway did

raw = client.chat.completions.with_raw_response.create(
    model="gpt-4o-mini", messages=[{"role": "user", "content": "Hi"}]
)
print(raw.headers.get("x-vidai-request-id"))  # paste into Request logs › Request reference
print(raw.headers.get("x-vidai-model"))       # the model that answered

Cost is never in the answer: find the call in Request logs.

Errors

The SDKs raise their usual exceptions; match on the x-vidai-error-code header. A notebook's typical ones:

Status Gateway code What it means
401 invalid_api_key, missing_api_key The secret is missing, misspelt, or Notebook access is off
403 content_guardrail_blocked A guardrail stopped the content, for example personal data from a dataset
403 model_not_allowed Your key may not call that model
429 rate_limit_exceeded, token_limit_exceeded A loop over many rows went too fast; slow it down

The full list is on the OpenAI SDK for Python page.

Model names

Use the names your organisation has approved, as listed under Models in the Control room. client.models.list() (OpenAI SDK) returns exactly the models your key may call.

What goes through the gateway

In Colab Through the gateway
Your code calling an SDK pointed at the gateway Yes, to every provider your organisation has set up
Gemini in Colab (the built-in assistant, code completion) No: it uses Google's own models
Libraries built on these SDKs (LangChain and others) Yes, when you give them the same address and key

Check it works in a minute

Run the OpenAI cell above. ok means the address and key are right. The call shows in Request logs within seconds.

Good to know

  • Colab runs in Google's cloud: the gateway must be reachable from the internet. A gateway only on your private network can't be reached from Colab.
  • Secrets belong to your Google account. A notebook you share doesn't share the secret: each person adds their own key, so each person's calls show under their name.
  • Never print the key or leave it in a cell's output; a shared notebook keeps its outputs.
  • A loop over a dataframe can send thousands of calls; your key's rate and token limits apply, and the gateway's own 429 has no Retry-After header, so pause between batches.