> ## Documentation Index
> Fetch the complete documentation index at: https://docs.apisale.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Google Gemini SDK

> Use the official @google/genai package against apisale.

Point the [official Google Gen AI SDK](https://www.npmjs.com/package/@google/genai) at apisale. Paths under `/v1beta/models` match Google's API layout.

## Install

```bash theme={null}
npm install @google/genai
```

## Configure client

```typescript theme={null}
import { GoogleGenAI } from "@google/genai";

const ai = new GoogleGenAI({
  apiKey: process.env.APISALE_API_KEY,
  httpOptions: {
    baseUrl: "https://api.apisale.ai",
  },
});
```

Use your apisale key (`sk-...`) as `apiKey`.

<Note>
  If your SDK version only supports API key header, set `apiKey` to your apisale key. For raw REST, use `Authorization: Bearer $APISALE_API_KEY`.
</Note>

## List models

```typescript theme={null}
const pager = await ai.models.list();
for await (const model of pager) {
  console.log(model.name);
}
```

REST:

```bash theme={null}
curl "https://api.apisale.ai/v1beta/models" \
  -H "Authorization: Bearer $APISALE_API_KEY"
```

## Generate images (sync)

```typescript theme={null}
const response = await ai.models.generateContent({
  model: "gemini-2.5-flash-image",
  contents: "A watercolor illustration of a fox in autumn leaves",
});

// Image bytes are in response.candidates[0].content.parts
```

With a reference image (image-to-image), include image parts in `contents` per Gemini SDK docs — apisale detects image input and routes to `image-to-image`.

| SDK model ID             | Image op   | apisale slug             |
| ------------------------ | ---------- | ------------------------ |
| `gemini-2.5-flash-image` | text/image | `google/nano-banana/...` |
| `nano-banana`            | text/image | `google/nano-banana/...` |

## Generate video (async)

Video models (`veo-3.1`, etc.) return a **job-style** response. Poll using the operation/run id returned in the response until complete.

```typescript theme={null}
const op = await ai.models.generateContent({
  model: "veo-3.1",
  contents: "Slow motion coffee pour, macro lens",
});

// When the response includes a run/job id, poll until done
// (exact shape matches Gemini video preview APIs — see response for status field)
```

REST: `POST /v1beta/models/{model}:generateContent`

apisale maps:

| SDK model ID                  | Video op       | apisale slug                    |
| ----------------------------- | -------------- | ------------------------------- |
| `veo-3.1`                     | text-to-video  | `google/veo-3.1/text-to-video`  |
| `veo-3.1` + image in contents | image-to-video | `google/veo-3.1/image-to-video` |

## curl example

```bash theme={null}
curl -X POST "https://api.apisale.ai/v1beta/models/gemini-2.5-flash-image:generateContent" \
  -H "Authorization: Bearer $APISALE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "contents": [{
      "role": "user",
      "parts": [{ "text": "A minimalist logo for a coffee brand" }]
    }]
  }'
```

## Python

```python theme={null}
from google import genai
import os

client = genai.Client(
    api_key=os.environ["APISALE_API_KEY"],
    http_options={"base_url": "https://api.apisale.ai"},
)

response = client.models.generate_content(
    model="gemini-2.5-flash-image",
    contents="A neon cityscape at night",
)
print(response)
```

## Related

* [SDK-compatible models](/sdk-compat/generated/models) — live ID → slug table
* [OpenAI SDK](/sdk-compat/openai-sdk) — image/video via OpenAI client
* [Account monitoring](/get-started/account-and-monitoring)
