Are you an LLM? Read llms.txt for a summary of the docs, or llms-full.txt for the full context.
Skip to content
Guides

Connect with Gemini

In an SDK, update where you create your client: give it Mubit's base URL and your Mubit key. With curl, change the URL and the key in its header. Keep your model IDs and the rest of your code.

ℹ️Note

If the console doesn't list Gemini under the starter credit, add your Gemini key under Provider keys first, as the Provider keys page shows.

Base URL

The base URL is https://api.mubit.ai/gemini. Leave the version path off the end: the SDK adds /v1beta.

Use the base URL your console's Connect page shows.

Key

Pass your Mubit key as the SDK's API key. The SDK sends it in the x-goog-api-key header. If you call the API without the SDK, send the key in x-goog-api-key too, not in ?key=.

The examples read the key from MUBIT_API_KEY. To create a key and set it, follow step 1 of the Quickstart.

Send a call

Install the SDK: pip install google-genai for Python, or npm install @google/genai for TypeScript.

Python
import os
from google import genai
from google.genai import types
 
client = genai.Client(
    api_key=os.environ["MUBIT_API_KEY"],
    http_options=types.HttpOptions(
        base_url="https://api.mubit.ai/gemini",  # no /v1beta
    ),
)
 
instructions = (
    "Sort the support message into one category: "
    "billing, bug, account or other. Reply with the category only."
)
 
response = client.models.generate_content(
    model="gemini-3.8-flash",
    contents="I was charged twice for my October invoice.",
    config=types.GenerateContentConfig(system_instruction=instructions),
)
print(response.text)

The TypeScript examples use top-level await, so run them as ES modules: save the file as gemini.mts and run npx tsx gemini.mts, or add "type": "module" to your package.json.

If the call answers 403 provider_key_missing, your project has no Gemini key yet.

Stream the answer

Use the SDK's stream method, or call :streamGenerateContent. Mubit streams the answer back to your app.

Python
import os
from google import genai
from google.genai import types
 
client = genai.Client(
    api_key=os.environ["MUBIT_API_KEY"],
    http_options=types.HttpOptions(
        base_url="https://api.mubit.ai/gemini",  # no /v1beta
    ),
)
 
for chunk in client.models.generate_content_stream(
    model="gemini-3.8-flash",
    contents="I was charged twice for my October invoice.",
    config=types.GenerateContentConfig(
        system_instruction="Reply to the support message in two short sentences.",
    ),
):
    print(chunk.text or "", end="", flush=True)
print()

With ?alt=sse, the answer comes as server-sent events. curl -N prints each event as it arrives.

Or set the SDK's environment variables

The Gemini SDKs read their base URL and key from the environment when your code doesn't pass them. To point an app at Mubit without a code change, run these lines in the shell where the app runs:

export GOOGLE_GEMINI_BASE_URL=https://api.mubit.ai/gemini
export GEMINI_API_KEY="$MUBIT_API_KEY"
unset GOOGLE_API_KEY

The SDKs use GOOGLE_API_KEY before GEMINI_API_KEY, so the last line unsets it. A Google key left in the shell would go out in place of your Mubit key.

See the call in Requests

  1. In the console, open Requests.
  2. Find your call at the top. The list is newest first.
  3. Check Model asked. It shows the model ID from your call.
  4. Select the row. The call opens with its Request and its Reply.

A streamed call shows its whole reply.

What Mubit forwards and trains on

  • Forwarded: when Mubit sends a call on to Gemini, it sends your request with your Gemini key, or the starter credit's key, in place of your Mubit key. It doesn't pass on cookies, x-middleware-store or x-middleware-record.
  • Trained on: adapters train only on kept examples: the recorded calls Mubit accepts for a task. A call recorded without its request and reply is never a kept example.

Frameworks and coding tools

Frameworks covers the Vercel AI SDK, and Coding tools covers Gemini CLI. To call Gemini through the OpenAI SDK, use the base URL https://api.mubit.ai/gemini/v1beta/openai. On the starter credit, this base URL gets 403 starter_credit_route: add your own Gemini key to use it.

If a call fails

The error names its code. Troubleshooting lists the codes and what to do. Each answer carries the call's ID in the x-middleware-request-id header: see Find a call's request ID.

Next