{"record":{"id":"48e27f185c06f43f","repo":"upstash/context7","slug":"api-key-should-start-with-api-key-prefix","errorCode":null,"errorMessage":"API key should start with '${API_KEY_PREFIX}'","messagePattern":"API key should start with '(.+?)'","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"packages/sdk/src/client.ts","lineNumber":38,"sourceCode":"export type * from \"@commands/types\";\nexport type {\n  AuthTokenProvider,\n  CacheSetting,\n  Context7Fetch,\n  Context7ResponseMetadata,\n  RateLimitMetadata,\n  RetryConfig,\n} from \"@http\";\nexport * from \"@error\";\n\nexport class Context7 {\n  private readonly httpClient: HttpClient;\n\n  constructor(config: Context7Config = {}) {\n    const credential = resolveCredential(config);\n\n    if (credential.kind === \"apiKey\" && !credential.value.startsWith(API_KEY_PREFIX)) {\n      console.warn(`API key should start with '${API_KEY_PREFIX}'`);\n    }\n\n    this.httpClient = new HttpClient({\n      baseUrl: config.baseUrl ?? DEFAULT_BASE_URL,\n      headers: {\n        ...withoutAuthorizationHeader(config.headers),\n      },\n      authToken: credential.value,\n      retry: config.retry,\n      cache: config.cache ?? \"no-store\",\n      timeout: config.timeout,\n      signal: config.signal,\n      keepAlive: config.keepAlive,\n      fetch: config.fetch,\n      onResponse: config.onResponse,\n    });\n  }\n","sourceCodeStart":20,"sourceCodeEnd":56,"githubUrl":"https://github.com/upstash/context7/blob/4416fb855b8f752be735e34f943b5d0762701aad/packages/sdk/src/client.ts#L20-L56","documentation":"The Context7 SDK client constructor warns when an API key credential does not start with the expected API_KEY_PREFIX. It is a non-fatal warning: the client is still constructed and the key is sent as-is, but authentication will likely fail if the key is malformed.","triggerScenarios":"Creating `new Context7({ apiKey })` where resolveCredential returns kind \"apiKey\" and the value does not start with API_KEY_PREFIX (e.g. passing a raw token, an OAuth secret, or a key with extra whitespace/characters).","commonSituations":"Copy-pasting the wrong credential type from the dashboard; including a \"Bearer \" prefix manually; trimming/pasting errors; confusion between API keys and other token formats.","solutions":["Copy the API key exactly as shown in the Context7 dashboard, including its prefix.","Strip any manually added \"Bearer \" or surrounding whitespace before passing it.","Confirm you are using an API key, not another credential type (e.g. OAuth token).","If using a non-key credential intentionally, pass it via headers/config so it is not treated as an apiKey."],"exampleFix":"// before\nconst client = new Context7({ apiKey: 'Bearer abc123' });\n// after\nconst client = new Context7({ apiKey: process.env.CONTEXT7_API_KEY!.trim() }); // value starts with the expected prefix","handlingStrategy":"validation","validationCode":"const key = process.env.CONTEXT7_API_KEY;\nif (!key || !key.startsWith(API_KEY_PREFIX)) throw new Error('CONTEXT7_API_KEY must start with ' + API_KEY_PREFIX);","typeGuard":"const isValidApiKey = (v: string): v is `ctx7sk-${string}` => v.startsWith('ctx7sk-');","tryCatchPattern":null,"preventionTips":["Copy the key verbatim from the dashboard; never prepend 'Bearer '.","Trim whitespace before constructing the client.","Load the key from env, not hardcoded strings that get mangled.","Add a startup assertion on the key format in your app bootstrap."],"tags":["authentication","api-key","configuration"],"backgroundTag":"invalid-argument-format","analyzedSha":"4416fb855b8f752be735e34f943b5d0762701aad","analyzedAt":"2026-09-16T20:28:07.148Z","contentChangedAt":"2026-09-16T20:28:07.148Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}