{"reason": "error", "error": "type='realtime_model...
# ask-ai
s
Copy code
{
  "reason": "error",
  "error": "type='realtime_model_error' timestamp=1759228075.8803654 label='livekit.plugins.google.beta.realtime.realtime_api.RealtimeModel' error=ConnectionClosedError(Close(code=1008, reason='API keys are not supported by this API. Expected OAuth2 access token or other authentication credentials that assert a prin'), Close(code=1008, reason='API keys are not supported by this API. Expected OAuth2 access token or other authentication credentials that assert a prin'), True) recoverable=False"
}
t
Thanks for reaching out, Ajay. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
The error you're seeing suggests that API keys aren't supported here, and instead, OAuth2 access tokens are expected. Are you running into this issue when trying to connect to a LiveKit room, or is it happening while working with a third-party API inside your LiveKit application? If you could share a bit more about the situation, I'd be happy to help you get to the bottom of it! Sources: README.md | livekit-api/src/services/mod.rs | tools/server/tests/unit/test_security.py | plugins/openai/src/realtime/realtime_model.ts | Agent Testing & Evaluation | livekit/livekit_composite | DeepWiki
s
in livekit
t
Hi there! I see you're encountering an error because LiveKit expects a properly generated JSON Web Token (JWT) for client-side room connections, rather than raw API keys or secrets. No worries—let me guide you through how to fix this: 1. Generate a JWT Access Token: • On your server, use your
LIVEKIT_API_KEY
and
LIVEKIT_API_SECRET
to create a signed JWT. • Make sure to include the necessary permissions (like
roomJoin
,
canPublish
, and
canSubscribe
), along with the room name and participant identity. Here’s an example in Node.js to help you out:
Copy code
import { AccessToken } from 'livekit-server-sdk';

const apiKey = process.env.LIVEKIT_API_KEY;
const apiSecret = process.env.LIVEKIT_API_SECRET;
const roomName = 'my-room';
const participantIdentity = 'user1';

const token = new AccessToken(apiKey, apiSecret, {
  identity: participantIdentity,
  ttl: '1h',
});

token.addGrant({
  roomJoin: true,
  room: roomName,
  canPublish: true,
  canSubscribe: true,
});

const jwtToken = await token.toJwt();
// Send this token to the client
2. Use the Token on the Client:
Copy code
const room = new Room();
await room.connect('wss://your-server.livekit.cloud', jwtToken);
Just a quick reminder: Please avoid using
LIVEKIT_API_KEY
or
LIVEKIT_API_SECRET
directly in your client-side code. Generating and using a JWT token is the safest way to go. If you have any questions or need a hand with this, feel free to reach out—I’m here to help! Sources: frontend/lib/server-utils.ts | packages/rpc-demo/.env.local | packages/react/src/components/LiveKitRoom.tsx | Authentication | LiveKit Docs | Connecting to LiveKit | LiveKit Docs
s
using python
t
Hi there! To help you generate a JWT access token for LiveKit using Python, here’s a simple step-by-step guide: 1. First, install the LiveKit API package:
Copy code
pip install livekit-api
2. Next, generate the token with this code:
Copy code
from livekit import api
import os

# Set your API key and secret
api_key = os.getenv("LIVEKIT_API_KEY")
api_secret = os.getenv("LIVEKIT_API_SECRET")

# Create the token
token = (
    api.AccessToken(api_key, api_secret)
    .with_identity("your-identity")
    .with_grants(
        api.VideoGrants(
            room_join=True,
            room="your-room-name"
        )
    )
    .to_jwt()
)

print(token)  # Send this token to the client
3. If you'd like, you can also add an expiry time (TTL) like this:
Copy code
import datetime

token = (
    api.AccessToken(api_key, api_secret)
    .with_identity("your-identity")
    .with_grants(
        api.VideoGrants(
            room_join=True,
            room="your-room-name"
        )
    )
    .with_ttl(datetime.timedelta(hours=1))  # Token expires in 1 hour
    .to_jwt()
)
4. Finally, use the token on the client side:
Copy code
const room = new Room();
await room.connect('wss://your-server.livekit.cloud', jwtToken);
Just a quick reminder to replace
your-identity
and
your-room-name
with the actual participant identity and room name you want to use. If you have any questions or need a hand with anything else, feel free to ask—I’m here to help! Sources: auth.py | Authentication | LiveKit Docs | Docs::Agents | Generating tokens | LiveKit Docs | examples/agent_dispatch.py