{"record":{"id":"a6618d24907d338b","repo":"vercel/ai","slug":"invalid-auth-expected-an-authentication-mode-or-a","errorCode":null,"errorMessage":"Invalid auth: expected an authentication mode or a flat record with string values.","messagePattern":"Invalid auth: expected an authentication mode or a flat record with string values\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"packages/harness/src/utils/authentication-environment.ts","lineNumber":14,"sourceCode":"import type { HarnessV1AuthenticationEnvironment } from '../v1/harness-authentication';\n\nexport function isHarnessAuthenticationEnvironment(\n  value: unknown,\n): value is HarnessV1AuthenticationEnvironment {\n  if (value == null || typeof value !== 'object') {\n    return false;\n  }\n\n  if (\n    Array.isArray(value) ||\n    Object.values(value).some(entry => typeof entry !== 'string')\n  ) {\n    throw new TypeError(\n      'Invalid auth: expected an authentication mode or a flat record with string values.',\n    );\n  }\n\n  return true;\n}\n","sourceCodeStart":1,"sourceCodeEnd":21,"githubUrl":"https://github.com/vercel/ai/blob/69428b1f8b037e4d118fb4853428d5c4e620493c/packages/harness/src/utils/authentication-environment.ts#L1-L21","documentation":"isHarnessAuthenticationEnvironment accepts either a recognized authentication mode or a flat record whose values are all strings. An array, or an object with non-string values (numbers, booleans, nested objects), is rejected with this TypeError because auth environment variables must be flat string-to-string maps.","triggerScenarios":"Passing auth as an array of pairs, a nested object ({ credentials: { token } }), or values like { PORT: 8080 } / { DEBUG: true } to the harness authentication option.","commonSituations":"Reusing a process.env-like object typed loosely; loading JSON config where numbers/booleans aren't stringified; accidentally passing an env array from another API.","solutions":["Convert every value to a string: PORT: '8080', DEBUG: 'true'.","Flatten nested objects into flat string entries (or pass a supported authentication mode instead).","If passing an array by mistake, convert it to an object: Object.fromEntries(pairs)."],"exampleFix":"// before\nconst auth = { apiKey: 'sk-...', retries: 3 };\n// after\nconst auth = { apiKey: 'sk-...', retries: String(3) };","handlingStrategy":"validation","validationCode":"const valid = auth != null && !Array.isArray(auth) && Object.values(auth).every(v => typeof v === 'string');","typeGuard":"function isFlatStringRecord(v: unknown): v is Record<string, string> { return typeof v === 'object' && v !== null && !Array.isArray(v) && Object.values(v).every(x => typeof x === 'string'); }","tryCatchPattern":"try { createHarness({ auth }); } catch (e) { if (e instanceof TypeError && e.message.includes('Invalid auth')) { auth = Object.fromEntries(Object.entries(auth).map(([k, v]) => [k, String(v)])); createHarness({ auth }); } else throw e; }","preventionTips":["Type auth as Record<string, string> so non-string values fail at compile time","Stringify env values when loading from JSON config","Never pass arrays or nested objects as auth environment"],"tags":["authentication","typescript","validation","environment"],"backgroundTag":"invalid-auth-config","analyzedSha":"69428b1f8b037e4d118fb4853428d5c4e620493c","analyzedAt":"2026-08-30T12:32:21.016Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}