{"record":{"id":"2682e10c67c0424c","repo":"paperclipai/paperclip","slug":"failed-to-create-agent-api-key","errorCode":null,"errorMessage":"Failed to create agent API key","messagePattern":"Failed to create agent API key","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"cli/src/commands/client/token.ts","lineNumber":78,"sourceCode":"\nexport function registerTokenCommands(program: Command): void {\n  const token = program.command(\"token\").description(\"Manage Paperclip API tokens\");\n  const agent = token.command(\"agent\").description(\"Manage agent API keys\");\n\n  addCommonClientOptions(\n    agent\n      .command(\"create\")\n      .description(\"Create an agent API key\")\n      .requiredOption(\"-C, --company-id <id>\", \"Company ID\")\n      .requiredOption(\"--agent <agent>\", \"Agent ID, shortname, or unambiguous name\")\n      .option(\"--name <name>\", \"API key label\", \"cli-agent\")\n      .action(async (opts: AgentTokenOptions) => {\n        try {\n          const ctx = resolveCommandContext(opts, { requireCompany: true });\n          const agentRow = await resolveAgent(ctx.api, ctx.companyId ?? \"\", opts.agent ?? \"\");\n          const payload = createAgentKeySchema.parse({ name: opts.name });\n          const key = await ctx.api.post<CreatedAgentKey>(apiPath`/api/agents/${agentRow.id}/keys`, payload);\n          if (!key) throw new Error(\"Failed to create agent API key\");\n          printOutput(\n            {\n              agentId: agentRow.id,\n              agentName: agentRow.name,\n              companyId: agentRow.companyId,\n              key,\n            },\n            { json: ctx.json },\n          );\n        } catch (err) {\n          handleCommandError(err);\n        }\n      }),\n    { includeCompany: false },\n  );\n\n  addCommonClientOptions(\n    agent","sourceCodeStart":60,"sourceCodeEnd":96,"githubUrl":"https://github.com/paperclipai/paperclip/blob/120ae5428fa29bee300bcf806491cd4d965fbb7c/cli/src/commands/client/token.ts#L60-L96","documentation":"token agent create posted the key creation and got a falsy result, so no key material is available to display/export; a sentinel guard on the API response.","triggerScenarios":"Thrown at cli/src/commands/client/token.ts:78 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Verify credentials and server reachability, then retry creating the agent API key."],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"120ae5428fa29bee300bcf806491cd4d965fbb7c","analyzedAt":"2026-08-18T22:49:45.177Z","contentChangedAt":"2026-08-18T22:49:45.177Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}