{"record":{"id":"275b87e63c3c209b","repo":"vercel/ai","slug":"cartesia-realtime-client-secret-request-failed","errorCode":null,"errorMessage":"Cartesia realtime client secret request failed: ${response.status} ${text}","messagePattern":"Cartesia realtime client secret request failed: (.+?) (.+?)","errorType":"http","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/cartesia/src/cartesia-realtime-model.ts","lineNumber":103,"sourceCode":"      throw new Error('Cartesia Ink 2 currently supports English only.');\n    }\n\n    const fetchFn = this.config.fetch ?? fetch;\n    const response = await fetchFn(`${this.config.baseURL}/access-token`, {\n      method: 'POST',\n      headers: {\n        ...this.config.headers(),\n        'Content-Type': 'application/json',\n      },\n      body: JSON.stringify({\n        grants: { stt: true },\n        ...(expiresIn != null ? { expires_in: expiresIn } : {}),\n      }),\n    });\n\n    if (!response.ok) {\n      const text = await response.text();\n      throw new Error(\n        `Cartesia realtime client secret request failed: ${response.status} ${text}`,\n      );\n    }\n\n    const data = (await response.json()) as { token?: unknown };\n    if (typeof data.token !== 'string' || data.token.length === 0) {\n      throw new Error(\n        'Cartesia realtime client secret response did not include a token.',\n      );\n    }\n\n    const turnDetection = sessionConfig?.turnDetection;\n    const useTurnDetection =\n      turnDetection === undefined ||\n      (turnDetection !== null && turnDetection.type !== 'disabled');\n    const inputAudioFormat = sessionConfig?.inputAudioFormat;\n    const url = new URL(\n      useTurnDetection","sourceCodeStart":85,"sourceCodeEnd":121,"githubUrl":"https://github.com/vercel/ai/blob/69428b1f8b037e4d118fb4853428d5c4e620493c/packages/cartesia/src/cartesia-realtime-model.ts#L85-L121","documentation":"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.","triggerScenarios":"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.","commonSituations":"Missing or wrong CARTESIA_API_KEY (401/403); keys created without realtime scopes; network proxies or WAFs returning error pages (HTML bodies); Cartesia outages.","solutions":["Read the status and body text in the error message to identify the API's stated reason (401 → auth, 400 → bad request).","Verify the CARTESIA_API_KEY environment variable is set, valid, and unexpired.","Confirm the API key has realtime/access-token permissions on your Cartesia account.","Retry on 5xx; check https://status.cartesia.com for outages."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// before calling, ensure the key exists and baseURL is correct\nif (!process.env.CARTESIA_API_KEY) throw new Error('CARTESIA_API_KEY is not set');\nif (!/^https:\\/\\/api\\.cartesia\\.ai/.test(baseURL)) console.warn('Unexpected Cartesia baseURL');","typeGuard":null,"tryCatchPattern":"try {\n  return await model.doCreateClientSecret(options);\n} catch (e) {\n  const m = /request failed: (\\d{3})/.exec(String(e.message));\n  const status = m ? Number(m[1]) : 0;\n  if (status >= 500) return retry(() => model.doCreateClientSecret(options), 3);\n  if (status === 401 || status === 403) throw new Error('Check CARTESIA_API_KEY and its realtime permissions: ' + e.message);\n  throw e;\n}","preventionTips":["Verify CARTESIA_API_KEY is present, valid, and has realtime scopes.","Retry with backoff only on 429/5xx; fail fast on 4xx auth errors.","Confirm baseURL points to api.cartesia.ai; beware proxies returning error pages."],"tags":["network","authentication","http-error","realtime"],"backgroundTag":"http-request-failed","analyzedSha":"69428b1f8b037e4d118fb4853428d5c4e620493c","analyzedAt":"2026-08-30T12:32:21.016Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}