OpenModelOpenModel
SDKs & Libraries

Google GenAI SDK

Use the official Google GenAI SDK with OpenModel by changing the base URL

The official Google GenAI SDK works with OpenModel out of the box. Point it to the OpenModel base URL and use your OpenModel API key to access Gemini models.

Installation

pip install google-genai

Configuration

Python

from google import genai

client = genai.Client(
    api_key="om-your-api-key",
    http_options={"api_version": "v1beta", "url": "https://api.openmodel.ai"},
)

Node.js

import { GoogleGenAI } from "@google/genai"

const ai = new GoogleGenAI({
  apiKey: "om-your-api-key",
  httpOptions: { apiVersion: "v1beta", baseUrl: "https://api.openmodel.ai" },
})

Note: The api_version must be set to "v1beta" and the base URL should be https://api.openmodel.ai (without a trailing path). The SDK constructs the full endpoint automatically.

Environment Variables

The Google GenAI SDK reads GOOGLE_API_KEY by default. You can set it along with a custom base URL:

export GOOGLE_API_KEY="om-your-api-key"

Note: The SDK does not support setting the base URL via environment variables. You must pass http_options explicitly when constructing the client.

Examples

Basic Generation

from google import genai

client = genai.Client(
    api_key="om-your-api-key",
    http_options={"api_version": "v1beta", "url": "https://api.openmodel.ai"},
)

response = client.models.generate_content(
    model="gemini-3.5-flash",
    contents="Explain how a neural network learns.",
)
print(response.text)

Streaming

from google import genai

client = genai.Client(
    api_key="om-your-api-key",
    http_options={"api_version": "v1beta", "url": "https://api.openmodel.ai"},
)

response = client.models.generate_content_stream(
    model="gemini-3.5-flash",
    contents="Write a detailed guide to making sourdough bread.",
)

for chunk in response:
    print(chunk.text, end="", flush=True)
print()

Multi-Turn Conversation

from google import genai
from google.genai.types import Content, Part

client = genai.Client(
    api_key="om-your-api-key",
    http_options={"api_version": "v1beta", "url": "https://api.openmodel.ai"},
)

response = client.models.generate_content(
    model="gemini-3.5-flash",
    contents=[
        Content(role="user", parts=[Part(text="What is the capital of France?")]),
        Content(role="model", parts=[Part(text="The capital of France is Paris.")]),
        Content(role="user", parts=[Part(text="What is its population?")]),
    ],
)
print(response.text)

System Instruction

from google import genai
from google.genai.types import GenerateContentConfig

client = genai.Client(
    api_key="om-your-api-key",
    http_options={"api_version": "v1beta", "url": "https://api.openmodel.ai"},
)

response = client.models.generate_content(
    model="gemini-3.5-flash",
    contents="Write a function to merge two sorted arrays.",
    config=GenerateContentConfig(
        system_instruction="You are an expert Python developer. Provide concise, production-ready code.",
    ),
)
print(response.text)

Error Handling

from google import genai
from google.genai.errors import ClientError, ServerError

client = genai.Client(
    api_key="om-your-api-key",
    http_options={"api_version": "v1beta", "url": "https://api.openmodel.ai"},
)

try:
    response = client.models.generate_content(
        model="gemini-3.5-flash",
        contents="Hello!",
    )
    print(response.text)
except ClientError as e:
    print(f"Client error: {e}")
except ServerError as e:
    print(f"Server error: {e}")

For comprehensive error handling patterns, see Error Handling.

Next Steps

On this page