{"record":{"id":"d875446074f3a195","repo":"paperclipai/paperclip","slug":"no-credential-found-set-sourceenvname-pass","errorCode":null,"errorMessage":"No credential found. Set ${sourceEnvName}, pass --api-key-env <variable>, or pass --api-key <value>.","messagePattern":"No credential found\\. Set (.+?), pass --api-key-env <variable>, or pass --api-key <value>\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"cli/src/commands/test-drive.ts","lineNumber":261,"sourceCode":"  if (model !== undefined && (!model || model.trim() !== model)) {\n    throw new Error(\"--model cannot be empty or have surrounding whitespace.\");\n  }\n  if (\n    harness === \"opencode\" &&\n    (!model || !/^openrouter\\/[^/\\s]+(?:\\/[^/\\s]+)*$/.test(model))\n  ) {\n    throw new Error(\n      \"OpenCode test drives require --model openrouter/<model>, with no empty path segments.\",\n    );\n  }\n\n  const sourceEnvName = options.apiKeyEnv?.trim() || definition.credentialTarget;\n  if (options.apiKeyEnv !== undefined && !/^[A-Za-z_][A-Za-z0-9_]*$/.test(sourceEnvName)) {\n    throw new Error(\"--api-key-env must name a valid environment variable.\");\n  }\n  const credential = options.apiKey ?? env[sourceEnvName];\n  if (!credential || credential.trim().length === 0) {\n    throw new Error(\n      `No credential found. Set ${sourceEnvName}, pass --api-key-env <variable>, or pass --api-key <value>.`,\n    );\n  }\n\n  return {\n    ...definition,\n    companyName,\n    agentName,\n    ...(model ? { model } : {}),\n    credential,\n    credentialSource: options.apiKey !== undefined ? \"--api-key\" : sourceEnvName,\n  };\n}\n\nfunction worktreeExecutionArmed(\n  settings: InstanceExperimentalSettings,\n  instanceId: string,\n): boolean {","sourceCodeStart":243,"sourceCodeEnd":279,"githubUrl":"https://github.com/paperclipai/paperclip/blob/01ad8584922b5d85292b1723cae71fa0d9b07a19/cli/src/commands/test-drive.ts#L243-L279","documentation":"After resolving the credential source environment variable (either --api-key-env or the app definition's credentialTarget), resolveTestDriveBootstrap checks that a non-empty credential is available. This error means no API key value could be found in the environment or on the command line for the test drive.","triggerScenarios":"Running test-drive when the resolved env var (e.g. the app's credentialTarget like OPENROUTER_API_KEY) is unset or empty, and neither --api-key-env pointing to a set variable nor --api-key <value> was supplied.","commonSituations":"Fresh machine or CI runner where the credential env var was never exported; variable exported in one shell but not the subshell running the CLI; typo'd variable name so env[sourceEnvName] is undefined.","solutions":["Export the expected variable, e.g. export OPENROUTER_API_KEY=<your-key>","Pass the key inline with --api-key <value> (avoid in shared shells/logs)","Point at a set variable with --api-key-env <VAR_NAME>","Check `echo $<sourceEnvName>` to confirm the variable is set and non-empty in the same shell"],"exampleFix":"// before\npaperclip test-drive someapp   # OPENROUTER_API_KEY unset\n// after\nexport OPENROUTER_API_KEY=sk-or-...\npaperclip test-drive someapp","handlingStrategy":"validation","validationCode":"const envName = apiKeyEnv?.trim() ?? 'OPENROUTER_API_KEY';\nif (!process.env[envName]?.trim() && !apiKey) {\n  throw new Error(`Set ${envName} or pass --api-key before running test-drive`);\n}","typeGuard":"function hasCredential(name: string): boolean {\n  return typeof process.env[name] === 'string' && process.env[name]!.trim().length > 0;\n}","tryCatchPattern":"try {\n  await runTestDrive(opts);\n} catch (e) {\n  if (String(e.message).startsWith('No credential found')) {\n    console.error(`Export ${envName} or pass --api-key`);\n    process.exit(1);\n  }\n  throw e;\n}","preventionTips":["Keep credentials in a .env file loaded by your shell profile","Verify with `printenv <VAR>` in the same shell before running CLI commands","Use --api-key only for one-off local runs, never in CI logs"],"tags":["cli","credentials","env-var"],"backgroundTag":"missing-api-key","analyzedSha":"01ad8584922b5d85292b1723cae71fa0d9b07a19","analyzedAt":"2026-09-10T03:14:50.855Z","contentChangedAt":"2026-09-10T03:14:50.855Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}