{"record":{"id":"b9c64c4543a55a0d","repo":"paperclipai/paperclip","slug":"environment-variable-opts-apikeyenv-trim-is-n","errorCode":null,"errorMessage":"Environment variable ${opts.apiKeyEnv.trim()} is not set","messagePattern":"Environment variable (.+?) is not set","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"cli/src/commands/client/prompt.ts","lineNumber":274,"sourceCode":"  if (!matches) {\n    throw new Error(\n      `Agent key belongs to ${agent.name} (${agent.id}), not '${reference}'. Use the matching agent or a board prompt.`,\n    );\n  }\n}\n\nfunction agentSummary(agent: Agent): PromptResult[\"agent\"] {\n  return {\n    id: agent.id,\n    name: agent.name,\n    urlKey: typeof agent.urlKey === \"string\" ? agent.urlKey : null,\n  };\n}\n\nfunction readApiKeyEnvOption(opts: PromptOptions): string | undefined {\n  if (!opts.apiKeyEnv?.trim()) return undefined;\n  const value = process.env[opts.apiKeyEnv.trim()]?.trim();\n  if (!value) throw new Error(`Environment variable ${opts.apiKeyEnv.trim()} is not set`);\n  return value;\n}\n","sourceCodeStart":256,"sourceCodeEnd":277,"githubUrl":"https://github.com/paperclipai/paperclip/blob/67001ec6eb96ae601aa27bc91d9b2415d665334a/cli/src/commands/client/prompt.ts#L256-L277","documentation":"`readApiKeyEnvOption` reads the env var named by `--api-key-env`. If the option is set (non-empty) but `process.env[<name>]` is empty/whitespace, it throws naming the variable. This lets the agent-prompt command pull the agent API key from a named env var instead of `--api-key`.","triggerScenarios":"Running `paperclipai agent prompt --api-key-env FOO ...` when `FOO` is not exported or is set to whitespace in the current shell/process.","commonSituations":"Typo in the env var name; the var is set in a different shell/session or `.env` file that was not sourced; CI secret not injected into the runner env; the var name was renamed but the CLI flag was not updated.","solutions":["Export the named variable in the running shell: `export FOO=<agent-key>` (or source the `.env`)","Check the spelling/case of the variable passed to `--api-key-env`","In CI, confirm the secret is mapped into the step's environment under that exact name"],"exampleFix":"# before\npaperclipai agent prompt --api-key-env AGENT_TOKEN \"do work\"   # AGENT_TOKEN unset\n# after\nexport AGENT_TOKEN=<agent-key>\npaperclipai agent prompt --api-key-env AGENT_TOKEN \"do work\"","handlingStrategy":"validation","validationCode":"function readEnvOrThrow(varName: string): string {\n  const value = process.env[varName.trim()]?.trim();\n  if (!value) throw new Error(`Environment variable ${varName.trim()} is not set`);\n  return value;\n}\nconst apiKey = opts.apiKeyEnv ? readEnvOrThrow(opts.apiKeyEnv) : undefined;","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Export the named env var in the shell/CI before running","Validate the var name spelling/case","Source the relevant `.env` file or inject the CI secret under the exact name"],"tags":["cli","env","auth","credentials","validation"],"backgroundTag":null,"analyzedSha":"67001ec6eb96ae601aa27bc91d9b2415d665334a","analyzedAt":"2026-08-12T12:05:45.408Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}