Getting a Firebase ID token
ODAI uses Firebase Authentication. Your client application must sign in through Firebase and retrieve an ID token to use with the API.getIdToken(true) to force a refresh, or rely on Firebase’s automatic token refresh and call getIdToken() before each request.
Passing the token
WebSocket connections
Pass the token as a query parameter when opening the WebSocket connection:token query parameter and closes the connection with code 1008 if authentication fails.
REST endpoints
Pass the token in theAuthorization header:
ODAI uses the raw token string in the
Authorization header — not the Bearer <token> format used by some APIs.Authentication flow
Client obtains a Firebase ID token
Your app authenticates the user with Firebase and calls
getIdToken() to retrieve a signed JWT.Client passes the token to ODAI
Include the token as
?token= for WebSocket connections or in the Authorization header for REST requests.Server validates the token
ODAI calls Firebase’s
verify_id_token() to confirm the token is valid and retrieves the associated user record from Firestore.Error responses
REST endpoints
| Status | Meaning |
|---|---|
401 | No token provided, token is invalid or expired, or the user is anonymous in a context that requires a registered account |
401, refresh your Firebase ID token and retry the request.
WebSocket connections
If authentication fails, the server closes the WebSocket with close code1008 (Policy Violation) and a message describing the reason. Reconnect with a fresh token.
Production vs. development
In production, ODAI enforces stricter authentication rules:- Anonymous users are rejected. The user must be signed in with a persistent Firebase account.
- Terms of service must be accepted. Users who have not accepted the terms receive a
401.