Skip to content

Comments

docs: add Google GenAI SDK tutorial (JS & Python)#21885

Open
Chesars wants to merge 3 commits intoBerriAI:mainfrom
Chesars:docs/google-genai-sdk-tutorial
Open

docs: add Google GenAI SDK tutorial (JS & Python)#21885
Chesars wants to merge 3 commits intoBerriAI:mainfrom
Chesars:docs/google-genai-sdk-tutorial

Conversation

@Chesars
Copy link
Contributor

@Chesars Chesars commented Feb 22, 2026

Relevant issues

N/A

Pre-Submission checklist

  • I have Added testing in the tests/litellm/ directory — N/A, docs-only change
  • My PR passes all unit tests on make test-unit — N/A, docs-only change
  • My PR's scope is as isolated as possible, it only solves 1 specific problem

Type

📖 Documentation

Changes

New tutorial: Google GenAI SDK with LiteLLM (docs/tutorials/google_genai_sdk.md)

Adds a comprehensive tutorial for using Google's official GenAI SDK (@google/genai for JavaScript/TypeScript, google-genai for Python) with LiteLLM Proxy. Includes:

  • Quick Start with tabs for JS, Python, and curl
  • Streaming examples
  • Multi-turn chat examples
  • Multi-provider routing via model_group_alias (call Claude, GPT-4o, Bedrock through the GenAI SDK)
  • Comparison table of pass-through (/gemini) vs native router endpoints
  • Environment variable configuration

Updated pass-through docs (docs/pass_through/google_ai_studio.md)

  • Replaced deprecated @google/generative-ai SDK examples with the new @google/genai SDK
  • Updated both the basic usage and tags examples

Sidebar (sidebars.js)

  • Added tutorial entry under "AI Tools" category, next to Gemini CLI

Tested locally

  • Pass-through route (/gemini/...) with Gemini 2.5 Flash
  • Native router route (/) with Gemini 2.5 Flash
  • Native router with model_group_alias routing to Anthropic Claude Sonnet — confirmed Claude responds through the GenAI SDK
  • Streaming verified

Add tutorial for using Google's official GenAI SDK (@google/genai for JS,
google-genai for Python) with LiteLLM proxy. Covers pass-through and
native router endpoints, streaming, multi-turn chat, and multi-provider
routing via model_group_alias. Also updates pass-through docs to use the
new SDK replacing the deprecated @google/generative-ai.
@vercel
Copy link

vercel bot commented Feb 22, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
litellm Ready Ready Preview, Comment Feb 22, 2026 1:11pm

Request Review

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Feb 22, 2026

Greptile Summary

This PR adds a new tutorial for using Google's official GenAI SDK (@google/genai for JS, google-genai for Python) with LiteLLM Proxy, and updates the existing pass-through docs to use the new SDK instead of the deprecated @google/generative-ai package.

  • New tutorial (google_genai_sdk.md): Comprehensive guide covering quick start, streaming, multi-turn chat, multi-provider routing via model_group_alias, and a comparison table of pass-through vs native router endpoints. Well-structured with JS, Python, and curl examples throughout.
  • Pass-through docs update (google_ai_studio.md): Correctly migrates SDK examples from GoogleGenerativeAI to GoogleGenAI with updated API patterns for both basic usage and tags examples.
  • Sidebar update: Adds the new tutorial under the "AI Tools" category adjacent to the Gemini CLI entry.
  • Issue found: The Environment Variable Configuration section in the new tutorial is incomplete for the Python SDK — it omits the GOOGLE_GENAI_BASE_URL env var and uses GOOGLE_GENAI_API_KEY instead of GEMINI_API_KEY (which is used elsewhere in the docs). Without the base URL env var, Python SDK users following the env-var approach won't connect to the proxy.

Confidence Score: 4/5

  • This is a docs-only PR that is safe to merge after fixing the incomplete Python SDK env var section.
  • Documentation-only changes with no code impact. The SDK migration in the pass-through docs and the new tutorial are well-written. One issue found: the Environment Variable Configuration section is incomplete for the Python SDK (missing base URL, inconsistent API key name). This could mislead Python developers trying to configure via env vars.
  • docs/my-website/docs/tutorials/google_genai_sdk.md — the Environment Variable Configuration section (lines 386-393) needs the Python SDK base URL env var added and the API key env var name corrected for consistency.

Important Files Changed

Filename Overview
docs/my-website/docs/tutorials/google_genai_sdk.md New comprehensive tutorial for using Google GenAI SDK with LiteLLM. Well-structured with JS/Python/curl examples. One issue: the Environment Variable Configuration section is incomplete for the Python SDK (missing base URL env var, inconsistent API key env var name).
docs/my-website/docs/pass_through/google_ai_studio.md Updated SDK examples from the deprecated @google/generative-ai package to the new @google/genai package. API patterns correctly updated (GoogleGenerativeAI → GoogleGenAI, model/requestOptions → httpOptions, etc.). Streaming and tags examples both updated consistently.
docs/my-website/sidebars.js Added new tutorial entry under the "AI Tools" category, correctly positioned next to the Gemini CLI tutorial entry. Single-line addition, no issues.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    SDK["Google GenAI SDK\n(@google/genai / google-genai)"]
    SDK -->|"baseUrl: /gemini"| PT["Pass-through Route\n/gemini/v1beta/models/..."]
    SDK -->|"baseUrl: /"| NR["Native Router Route\n/v1beta/models/..."]
    PT -->|"Direct proxy"| Gemini["Google Gemini API"]
    NR -->|"model_group_alias"| Router["LiteLLM Router"]
    Router --> Gemini
    Router --> Anthropic["Anthropic Claude"]
    Router --> OpenAI["OpenAI GPT-4o"]
    Router --> Bedrock["AWS Bedrock"]
    
    style PT fill:#e8f5e9,stroke:#4caf50
    style NR fill:#e3f2fd,stroke:#2196f3
    style Router fill:#fff3e0,stroke:#ff9800
Loading

Last reviewed commit: fa772cf

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

GOOGLE_GENAI_API_KEY does not exist in the google-genai SDK.
The correct env var is GEMINI_API_KEY (or GOOGLE_API_KEY).
Also note that the Python SDK has no base URL env var.
…ractions.md

The Python google-genai SDK does not read GOOGLE_GENAI_BASE_URL.
Use http_options={"base_url": "..."} in code instead.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant