Skip to main content
Vertex
Docs/Securing Ephemeral Client Tokens
5 min readv2.4
SecurityDifficulty: Advanced

Securing Ephemeral Client Tokens

Implement time-bounded, single-tenant scoped tokens for front-end browser clients without exposing production credentials.

By Devon K. (Staff Systems Engineer)•Published Oct 2, 2026

Securing Ephemeral Client Tokens

When building browser-based AI chats, search boxes, or mobile applications, your client code must never contain permanent API keys. Exposing vtx_live_ credentials in JavaScript bundles allows malicious users to extract your key and drain your quotas.


The Token Exchange Pattern

Browser Client              Your Backend Server                Vertex Edge
     │                               │                              │
     ├─── 1. Authenticate User ─────►│                              │
     │    (e.g. Session Cookie)      │                              │
     │                               ├─── 2. Request Ephemeral Key ─►
     │                               │    (With 15-min TTL)         │
     │                               │◄── 3. Return 'vtx_eph_...' ──┤
     │◄── 4. Deliver Client Token ───┤                              │
     │                                                              │
     ├────── 5. Direct Streaming Connection to Vertex Edge ────────►│

Token Minting Implementation

// On your Node.js/Next.js API route: /api/auth/vertex-token
export async function POST(req: Request) {
  const user = await verifyUserSession(req);
  if (!user) return new Response('Unauthorized', { status: 401 });

  const token = await vertexClient.credentials.createEphemeralToken({
    scope: ['read:namespaces', 'create:inference'],
    namespaceLimit: `tenant_${user.organizationId}`,
    ttlSeconds: 900 // 15 minutes
  });

  return Response.json({ token: token.secret, expiresAt: token.expiresAt });
}
Was this documentation page helpful?

Help us improve the Vertex developer experience.