Implementation:Googleapis Python genai Tokens
| Knowledge Sources | |
|---|---|
| Domains | Authentication, Tokens |
| Last Updated | 2026-02-15 14:00 GMT |
Overview
Concrete tool for creating ephemeral authentication tokens provided by the Google Gen AI SDK.
Description
The Tokens and AsyncTokens classes provide an experimental API module for creating short-lived authentication tokens. These tokens support configurable expiration times and usage constraints, and can include live connect configuration for WebSocket sessions. Only the Gemini Developer API (ML Dev) backend is supported.
Usage
Import this when you need to create ephemeral auth tokens for client-side applications that require limited-scope access to the Gemini API, particularly for Live API WebSocket sessions.
Code Reference
Source Location
- Repository: Googleapis_Python_genai
- File: google/genai/tokens.py
- Lines: 113-363 (Tokens at L113-266, AsyncTokens at L269-363)
Signature
class Tokens(_api_module.BaseModule):
def create(
self,
*,
config: Optional[types.CreateAuthTokenConfigOrDict] = None,
) -> types.AuthToken: ...
class AsyncTokens(_api_module.BaseModule):
async def create(
self,
*,
config: Optional[types.CreateAuthTokenConfigOrDict] = None,
) -> types.AuthToken: ...
Import
from google import genai
client = genai.Client(api_key="...")
# Access via: client.tokens
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| config | CreateAuthTokenConfigOrDict | No | Token configuration with expire_time, uses, and live_connect_constraints |
Outputs
| Name | Type | Description |
|---|---|---|
| create() returns | AuthToken | Ephemeral token with token string and metadata |
Usage Examples
from google import genai
from google.genai import types
client = genai.Client(api_key="GEMINI_API_KEY")
# Create an ephemeral auth token
token = client.tokens.create(
config=types.CreateAuthTokenConfig(
uses=1,
)
)
print(f"Token: {token.token}")