Skip to main content
Google’s officially recommended SDK is google-genai (the new one, replacing the older google-generativeai). Set http_options.base_url to point requests at OpenPAI.

Python

JavaScript / TypeScript

Streaming

Multimodal

Function calling

Thinking mode

Or just use a suffixed model ID (simpler):

Embeddings

Notes

  • When using the Gemini native protocol, the base URL is without /v1 (the SDK appends the /v1beta/models/... path automatically).
  • If your code originally uses the OpenAI-compatible path (/v1/chat/completions), you can leave it unchanged and just switch the model ID to gemini-*.
  • The OpenAI-compatible protocol automatically maps Gemini’s parts / inline_data to the content array, and vice versa.