# Google Gemini (/en/ai/platform/models/llm/gemini)

> For AI agents: see the complete documentation index at [llms.txt](/llms.txt).

> Documentation: Conversational AI.
> Documentation version: Preview.
> This document describes only this version. [Version index](/llms/doc-versions-convoai-guides-v2.txt).


Google Gemini provides advanced multimodal AI capabilities with fast performance and efficient processing for conversational AI applications.

## Sample configuration

Google Gemini supports BYOK only. It isn't available in managed mode. The following example starts an [ephemeral session](/en/ai/platform/get-started/start-stop-agent#test-a-configuration-without-saving-an-agent) with Gemini as the LLM. In an ephemeral session, you pass the agent configuration in the request, with your Gemini API key in the endpoint URL, and the Platform doesn't save them. Get your API key from [Google AI Studio](https://aistudio.google.com/app/apikey).

**Python SDK**

Pass your key as `api_key`, and leave it out of `url`. Call `create_session()` on an `Agent`. The SDK starts an ephemeral session when you set a Platform session option, such as `max_duration` in seconds.

```python
from agora_agent import Agent, DeepgramSTT, Gemini, OpenAITTS

test_agent = (
    Agent(client=client)
    .with_stt(DeepgramSTT(model="nova-3", language="en-US"))
    .with_llm(
        Gemini(
            api_key="<your_gemini_api_key>",
            model="gemini-3.6-flash",
            url="https://generativelanguage.googleapis.com/v1beta/models/gemini-3.6-flash:streamGenerateContent?alt=sse",
            max_history=32,
            failure_message="Hold on a second.",
            system_messages=[
                {"role": "system", "content": "You are a friendly support agent for Acme. Keep your answers short."}
            ],
        )
    )
    .with_tts(OpenAITTS(model="tts-1", voice="alloy"))
)

session = test_agent.create_session(
    channel="<your_channel_name>",
    token="<your_rtc_token>",
    agent_uid="1002",
    remote_uids=["1001"],
    max_duration=600,
)
session_id = session.start()
```

**TypeScript SDK**

Pass your key as `apiKey`, and leave it out of `url`. Call `createSession()` on an `Agent`. The SDK starts an ephemeral session when you set a Platform session option, such as `maxDuration` in seconds.

```ts
import { Agent, DeepgramSTT, Gemini, OpenAITTS } from 'agora-agents';

const testAgent = new Agent({ client })
  .withStt(new DeepgramSTT({ model: 'nova-3', language: 'en-US' }))
  .withLlm(
    new Gemini({
      apiKey: '<your_gemini_api_key>',
      model: 'gemini-3.6-flash',
      url: 'https://generativelanguage.googleapis.com/v1beta/models/gemini-3.6-flash:streamGenerateContent?alt=sse',
      maxHistory: 32,
      failureMessage: 'Hold on a second.',
      systemMessages: [
        { role: 'system', content: 'You are a friendly support agent for Acme. Keep your answers short.' },
      ],
    }),
  )
  .withTts(new OpenAITTS({ model: 'tts-1', voice: 'alloy' }));

const session = testAgent.createSession({
  channel: '<your_channel_name>',
  token: '<your_rtc_token>',
  agentUid: '1002',
  remoteUids: ['1001'],
  maxDuration: 600,
});
const sessionId = await session.start();
```

**Go SDK**

Pass your key as `APIKey`, and leave it out of `URL`. Call `CreateSession()` on an `Agent`. The SDK starts an ephemeral session when you set a Platform session option, such as `MaxDuration` in seconds.

```go
maxHistory := 32
testAgent := agentkit.NewAgent(client).
	WithStt(vendors.NewDeepgramSTT(vendors.DeepgramSTTOptions{Model: "nova-3", Language: "en-US"})).
	WithLlm(vendors.NewGemini(vendors.GeminiOptions{
		APIKey:         "<your_gemini_api_key>",
		Model:          "gemini-3.6-flash",
		URL:            "https://generativelanguage.googleapis.com/v1beta/models/gemini-3.6-flash:streamGenerateContent?alt=sse",
		MaxHistory:     &maxHistory,
		FailureMessage: "Hold on a second.",
		SystemMessages: []map[string]interface{}{
			{"role": "system", "content": "You are a friendly support agent for Acme. Keep your answers short."},
		},
	})).
	WithTts(vendors.NewOpenAITTS(vendors.OpenAITTSOptions{Model: "tts-1", Voice: "alloy"}))

maxDuration := 600
session := testAgent.CreateSession(agentkit.CreateSessionOptions{
	Channel:     "<your_channel_name>",
	Token:       "<your_rtc_token>",
	AgentUID:    "1002",
	RemoteUIDs:  []string{"1001"},
	MaxDuration: &maxDuration,
})
sessionID, err := session.Start(ctx)
if err != nil {
	log.Fatal(err)
}
```

**REST API**

Send a request to [Start an ephemeral session](/en/api-reference/api-ref/conversational-ai/platform/start-ephemeral-session). In the `llm` block, set `url` to the Gemini `streamGenerateContent` endpoint for your model, with `alt=sse` and your API key in the `key` query parameter. Set `credential.mode` to `byok`, and leave out `credential.fields`.

```bash
curl --request POST \
  --url https://preview.ai.agora.io/conversational-ai/v1/projects/<your_app_id>/sessions/ephemeral \
  --header 'Authorization: Basic <your_base64_encoded_credentials>' \
  --header 'Content-Type: application/json' \
  --data '
{
  "agent": {
    "instructions": "You are a friendly support agent for Acme. Keep your answers short.",
    "pipeline": {
      "mode": "cascaded",
      "asr": { "credential": { "mode": "managed" }, "vendor": "deepgram", "model": "nova-3", "language": "en-US" },
      "llm": {
        "credential": { "mode": "byok" },
        "vendor": "gemini",
        "style": "gemini",
        "model": "gemini-3.6-flash",
        "url": "https://generativelanguage.googleapis.com/v1beta/models/gemini-3.6-flash:streamGenerateContent?alt=sse&key=<your_gemini_api_key>",
        "max_history": 32,
        "failure_message": "Hold on a second."
      },
      "tts": {
        "credential": { "mode": "managed" },
        "vendor": "minimax",
        "params": { "model": "speech-2.6-turbo", "voice_setting": { "voice_id": "English_captivating_female1", "speed": 1 } }
      }
    }
  },
  "transport": {
    "type": "rtc",
    "channel": "<your_channel_name>",
    "token": "<your_rtc_token>",
    "uid": "1002",
    "subscribe_uids": ["1001"]
  }
}'
```

A saved agent can't have a key in its `url`. The response has the same format as Start a session. Set the system prompt and the greeting with the agent's `instructions` and `greeting`, not in the `llm` block.

## Key parameters

The `llm` block takes the following fields.

**llm**

**`vendor` (string) required**

Set to `gemini`.

**`credential` (object) required**

Set `mode` to `byok`.

**`style` (string) required**

Set to `gemini` to use Gemini's message format.

**`model` (string) required**

Refer to [Gemini models](https://ai.google.dev/gemini-api/docs/models/gemini) for available models.

**`url` (string) required**

The Gemini `streamGenerateContent` endpoint for your model, with `alt=sse` and `key=<your_gemini_api_key>`. Get your API key from [Google AI Studio](https://aistudio.google.com/app/apikey).

**`params` (object) optional**

**`ignore_empty` (boolean) optional**

Set to `true` to handle empty responses appropriately.

For complete `llm` block options, see [Create an agent](/en/api-reference/api-ref/conversational-ai/platform/create-agent). For advanced configuration options, model capabilities, and detailed parameter descriptions, see the [Google Gemini API documentation](https://ai.google.dev/api/generate-content#method:-models.streamgeneratecontent).
