> For clean Markdown of any page, append `.md` to the page URL.
> For a complete documentation index, see https://docs.sarvam.ai/llms.txt.
> For full documentation content in one file, see https://docs.sarvam.ai/llms-full.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.sarvam.ai/_mcp/server.

# Migrating from Gemini: Overview

> Common setup changes for teams moving from the Gemini API to Sarvam: base URL, auth header, SDK client, and error handling, shared across every guide in this section.

This page covers the setup changes that stay the same no matter which of your existing Gemini integrations you're moving over: base URL, auth header, and SDK client. Each product-specific migration guide already includes these same changes inline, so you don't need to read this page first; it's here as a standalone reference if you want the setup changes on their own.

## Quick start

Swap the client, then keep the rest of your code as-is:

```python
from google import genai

client = genai.Client(api_key="YOUR_GEMINI_API_KEY")
```

```python
from sarvamai import SarvamAI

client = SarvamAI(api_subscription_key="YOUR_SARVAM_API_KEY")
```

Both SDKs are also available for TypeScript/JavaScript; see [SDKs & Libraries](/api-reference-docs/sdks) for install instructions and language coverage.

For requests made directly over HTTP rather than through an SDK, the only change is the header and base URL:

```bash
curl -X POST "https://generativelanguage.googleapis.com/..." \
  -H "x-goog-api-key: YOUR_GEMINI_API_KEY"
```

```bash
curl -X POST https://api.sarvam.ai/... \
  -H "api-subscription-key: YOUR_SARVAM_API_KEY"
```

If your Gemini integration goes through the `openai` Python package pointed at Gemini's OpenAI-compatible endpoint rather than the native `google-genai` SDK, see the base URL and auth swap for that specific path in the [Chat Completion guide](/api-reference-docs/migrations/from-gemini/chat-completion): Sarvam's Chat Completions endpoint is OpenAI-compatible too, so that migration can be a two-line change.

## Base URL and auth

|                     | Gemini API                                  | Sarvam                            |
| ------------------- | ------------------------------------------- | --------------------------------- |
| Base URL            | `https://generativelanguage.googleapis.com` | `https://api.sarvam.ai`           |
| Auth header         | `x-goog-api-key: <api_key>`                 | `api-subscription-key: <api_key>` |
| Auth failure status | `401`                                       | `403`                             |

## Errors and rate limits

Sarvam returns `403` (not `401`) on authentication failures, and rate limits are enforced per API rather than account-wide. See [Errors & Troubleshooting](/api-reference-docs/errors-troubleshooting) and [Credits & Rate Limits](/api-reference-docs/ratelimits) for status codes and retry behavior. These apply the same way across every migration guide in this section.

## See also

* [Migrating Chat Completion](/api-reference-docs/migrations/from-gemini/chat-completion)
* [Migrating Text-to-Speech](/api-reference-docs/migrations/from-gemini/text-to-speech)
* [Migrating Speech-to-Text](/api-reference-docs/migrations/from-gemini/speech-to-text)
* [SDKs & Libraries](/api-reference-docs/sdks)
* [Errors & Troubleshooting](/api-reference-docs/errors-troubleshooting)