vercel/ai · error · Error

Cartesia realtime client secret request failed: ${response.s

Error message

Cartesia realtime client secret request failed: ${response.status} ${text}

What it means

After POSTing to {baseURL}/access-token, doCreateClientSecret checks response.ok. If the Cartesia API returns a non-2xx status, it throws an Error embedding the HTTP status and the raw response body text. This surfaces server-side auth, quota, or request-format failures from the token endpoint.

Source

Thrown at packages/cartesia/src/cartesia-realtime-model.ts:103

      throw new Error('Cartesia Ink 2 currently supports English only.');
    }

    const fetchFn = this.config.fetch ?? fetch;
    const response = await fetchFn(`${this.config.baseURL}/access-token`, {
      method: 'POST',
      headers: {
        ...this.config.headers(),
        'Content-Type': 'application/json',
      },
      body: JSON.stringify({
        grants: { stt: true },
        ...(expiresIn != null ? { expires_in: expiresIn } : {}),
      }),
    });

    if (!response.ok) {
      const text = await response.text();
      throw new Error(
        `Cartesia realtime client secret request failed: ${response.status} ${text}`,
      );
    }

    const data = (await response.json()) as { token?: unknown };
    if (typeof data.token !== 'string' || data.token.length === 0) {
      throw new Error(
        'Cartesia realtime client secret response did not include a token.',
      );
    }

    const turnDetection = sessionConfig?.turnDetection;
    const useTurnDetection =
      turnDetection === undefined ||
      (turnDetection !== null && turnDetection.type !== 'disabled');
    const inputAudioFormat = sessionConfig?.inputAudioFormat;
    const url = new URL(
      useTurnDetection

View on GitHub (pinned to 69428b1f8b)

Solutions

  1. Read the status and body text in the error message to identify the API's stated reason (401 → auth, 400 → bad request).
  2. Verify the CARTESIA_API_KEY environment variable is set, valid, and unexpired.
  3. Confirm the API key has realtime/access-token permissions on your Cartesia account.
  4. Retry on 5xx; check https://status.cartesia.com for outages.
Defensive patterns

Strategy: retry

Validate before calling

// before calling, ensure the key exists and baseURL is correct
if (!process.env.CARTESIA_API_KEY) throw new Error('CARTESIA_API_KEY is not set');
if (!/^https:\/\/api\.cartesia\.ai/.test(baseURL)) console.warn('Unexpected Cartesia baseURL');

Try / catch

try {
  return await model.doCreateClientSecret(options);
} catch (e) {
  const m = /request failed: (\d{3})/.exec(String(e.message));
  const status = m ? Number(m[1]) : 0;
  if (status >= 500) return retry(() => model.doCreateClientSecret(options), 3);
  if (status === 401 || status === 403) throw new Error('Check CARTESIA_API_KEY and its realtime permissions: ' + e.message);
  throw e;
}

Prevention

When it happens

Trigger: Any /access-token request that returns 401/403/400/500 etc. — invalid API key, revoked key, insufficient permissions, or malformed expires_in/session_config payload.

Common situations: Missing or wrong CARTESIA_API_KEY (401/403); keys created without realtime scopes; network proxies or WAFs returning error pages (HTML bodies); Cartesia outages.

Understand the failure class

Background: 'Something went wrong' / 'Request failed (500)' / 'HTTP error! status: 404' — what failed HTTP requests actually mean and how to find the real cause — this error's family across 28 libraries.

Related errors


AI-assisted analysis of vercel/ai@69428b1f8b (2026-08-30). Data as JSON: /api/errors/275b87e63c3c209b. Report an issue: GitHub.