hcengineering/platform · error

Token not specified

Error message

Token not specified

What it means

getClient in billing-client requires an auth token alongside the billing URL. If token is undefined, null, or empty, it throws because BillingClient cannot authenticate any request without it. Like the URL check, this fails fast at construction time.

Source

Thrown at packages/billing-client/src/client.ts:21

import {
  AiTokensData,
  AiTranscriptData,
  BillingStats,
  DatalakeStats,
  LiveKitEgressData,
  LiveKitEgressStats,
  LiveKitSessionData,
  LiveKitSessionsStats,
  LiveKitStats
} from './types'

/** @public */
export function getClient (billingUrl?: string, token?: string): BillingClient {
  if (billingUrl === undefined || billingUrl == null || billingUrl === '') {
    throw new Error('Billing url not specified')
  }
  if (token === undefined || token == null || token === '') {
    throw new Error('Token not specified')
  }

  return new BillingClient(billingUrl, token)
}

export class BillingClient {
  private readonly headers: Record<string, string>

  constructor (
    private readonly endpoint: string,
    private readonly token: string
  ) {
    this.headers = {
      Authorization: 'Bearer ' + token,
      'Content-Type': 'application/json'
    }
  }

View on GitHub (pinned to 63e28dc964)

Solutions

  1. Provide a valid billing token as the second argument to getClient.
  2. Check that the token env var/secret is present in the environment before creating the client.
  3. Load the token from your secret manager and fail fast at startup if absent.

Example fix

// before
const client = getClient(url) // token missing
// after
const token = process.env.BILLING_TOKEN
if (!token) throw new Error('BILLING_TOKEN is required')
const client = getClient(url, token)
Defensive patterns

Strategy: validation

Validate before calling

const token = process.env.BILLING_TOKEN
if (!token) throw new Error('BILLING_TOKEN env var is required')

Type guard

function isNonEmptyString(v: unknown): v is string {
  return typeof v === 'string' && v.trim().length > 0
}

Prevention

When it happens

Trigger: Calling getClient(billingUrl) without the second argument, or passing an empty/unset token variable (e.g. process.env.BILLING_TOKEN not set).

Common situations: Token env var missing in the deployment; token rotated/removed from secret store; calling code written for an older getClient signature that took only a URL.

Related errors


AI-assisted analysis of hcengineering/platform@63e28dc964 (2026-08-29). Data as JSON: /api/errors/248606b5e2a41aea. Report an issue: GitHub.