{"record":{"id":"1cd3e104b3f9a9e5","repo":"decolua/9router","slug":"you-com-search-requires-an-api-key","errorCode":null,"errorMessage":"You.com Search requires an API key","messagePattern":"You\\.com Search requires an API key","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"open-sse/handlers/search/callers.js","lineNumber":293,"sourceCode":"  });\n  if (params.country) qp.set(\"gl\", params.country.toLowerCase());\n  if (params.language) qp.set(\"hl\", params.language);\n\n  const page = toPageNumber(params.offset, params.maxResults);\n  if (page) qp.set(\"page\", String(page));\n\n  return {\n    url: `${resolveBaseUrl(config, params)}?${qp}`,\n    init: {\n      method: \"GET\",\n      headers: { Accept: \"application/json\" },\n    },\n  };\n}\n\nfunction buildYouComRequest(config, params) {\n  const apiKey = params.token;\n  if (!apiKey) throw new Error(\"You.com Search requires an API key\");\n\n  const { includes, excludes } = parseDomainFilter(params.domainFilter);\n  const qp = new URLSearchParams({\n    query: params.query,\n    count: String(Math.min(params.maxResults, 100)),\n  });\n\n  if (params.timeRange && params.timeRange !== \"any\") qp.set(\"freshness\", params.timeRange);\n  if (typeof params.offset === \"number\" && params.offset > 0 && params.maxResults > 0) {\n    qp.set(\"offset\", String(Math.min(Math.floor(params.offset / params.maxResults), 9)));\n  }\n  if (params.country) qp.set(\"country\", params.country);\n  if (params.language) qp.set(\"language\", params.language);\n  if (includes.length) qp.set(\"include_domains\", includes.join(\",\"));\n  if (excludes.length) qp.set(\"exclude_domains\", excludes.join(\",\"));\n\n  if (params.contentOptions?.full_page) {\n    qp.set(\"livecrawl\", params.searchType === \"news\" ? \"news\" : \"web\");","sourceCodeStart":275,"sourceCodeEnd":311,"githubUrl":"https://github.com/decolua/9router/blob/90b52e06ffd666b7929554211474d01588f6b1f8/open-sse/handlers/search/callers.js#L275-L311","documentation":"buildYouComRequest builds the request for the You.com search API, which requires a bearer API key. The builder validates params.token up front and throws this error when it is missing so the failure is immediate and self-explanatory rather than a 401 from You.com's servers.","triggerScenarios":"Calling the You.com search route with params.token undefined, null, or empty — no You.com API key configured for the account, or a hand-built params object omitting `token`.","commonSituations":"Provider enabled without obtaining a key from api.ydc-index.io; key saved to the wrong provider slot; env var not set when constructing params in scripts; account cleanup removed the credential.","solutions":["Obtain a You.com API key (ydc-index) and store it for the You.com provider in the dashboard","Ensure the call site passes token: '...' in params","Verify the key is non-empty and not whitespace (builder only checks falsy)","Check provider id spelling so the credential lookup resolves"],"exampleFix":"// before\nawait search({ provider: 'youcom', query: 'rust async', maxResults: 10 });\n// after\nawait search({ provider: 'youcom', query: 'rust async', maxResults: 10, token: process.env.YOU_API_KEY });","handlingStrategy":"validation","validationCode":"if (!params?.token || typeof params.token !== 'string' || !params.token.trim()) {\n  throw new Error('You.com search requires a non-empty token');\n}","typeGuard":"function hasYouComToken(params) {\n  return typeof params?.token === 'string' && params.token.trim().length > 0;\n}","tryCatchPattern":"try {\n  const res = await search({ provider: 'youcom', query, token });\n} catch (err) {\n  if (err.message.includes('requires an API key')) {\n    // configure the You.com key, then retry\n  } else throw err;\n}","preventionTips":["Set the You.com (ydc-index) key in your env and load it before calls","Validate credentials for the selected provider before dispatch","Keep one credential store so keys aren't scattered under wrong ids"],"tags":["api-key","search","youcom","configuration"],"backgroundTag":"missing-api-key","analyzedSha":"90b52e06ffd666b7929554211474d01588f6b1f8","analyzedAt":"2026-08-30T21:05:45.952Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}