{"record":{"id":"b8094cb4d567b2ff","repo":"decolua/9router","slug":"no-zed-organization-selected","errorCode":null,"errorMessage":"No Zed organization selected","messagePattern":"No Zed organization selected","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"open-sse/shared/zedAuth.js","lineNumber":261,"sourceCode":"  const token = credentials?.accessToken || credentials?.apiKey || \"\";\n  return `${userId}:${organizationId || \"default\"}:${token.slice(-16)}`;\n}\n\nfunction zedModelCacheKey(credentials) {\n  const psd = credentials?.providerSpecificData || {};\n  const org = psd.organizationId || psd.defaultOrganizationId || \"default\";\n  const token = credentials?.accessToken || credentials?.apiKey || \"\";\n  return `${psd.userId || \"unknown\"}:${org}:${token.slice(-16)}`;\n}\n\nexport async function fetchZedLlmToken(credentials, options = {}) {\n  const config = options.config || {};\n  let organizationId = options.organizationId || resolveZedOrganizationId(credentials);\n  if (!organizationId) {\n    const userInfo = await fetchZedAuthenticatedUser(credentials, options);\n    organizationId = resolveZedOrganizationId(credentials, userInfo);\n  }\n  if (!organizationId) throw new Error(\"No Zed organization selected\");\n\n  const cacheKey = zedUserCacheKey(credentials, organizationId);\n  const cached = llmTokenCache.get(cacheKey);\n  if (!options.forceRefresh && cached && cached.expiresAt > Date.now()) return cached.token;\n\n  const headers = {\n    \"Content-Type\": \"application/json\",\n    Accept: \"application/json\",\n    Authorization: buildZedUserAuthHeader(credentials),\n  };\n  const systemId = getSystemId(credentials);\n  if (systemId) headers[ZED_HEADERS.systemId] = systemId;\n\n  const data = await fetchJson(\n    zedUrl(config, \"cloudBaseUrl\", \"/client/llm_tokens\", ZED_CLOUD_BASE_URL),\n    {\n      method: \"POST\",\n      headers,","sourceCodeStart":243,"sourceCodeEnd":279,"githubUrl":"https://github.com/decolua/9router/blob/90b52e06ffd666b7929554211474d01588f6b1f8/open-sse/shared/zedAuth.js#L243-L279","documentation":"fetchZedLlmToken needs an organizationId before it can request an LLM token. It resolves it from options/config, then falls back to calling fetchZedAuthenticatedUser and resolving from the user info. If no organization can be resolved from either source, it throws \"No Zed organization selected\".","triggerScenarios":"Calling fetchZedLlmToken when neither credentials.providerSpecificData.organizationId/defaultOrganizationId nor the /client/users/me response yields an organization id — e.g. the Zed account belongs to no organization, or userInfo has an unexpected shape.","commonSituations":"Fresh Zed account with no org membership; enterprise SSO account where org ids live in a different field; stale cached user info; user never picked a default org in the dashboard config.","solutions":["Set providerSpecificData.organizationId (or defaultOrganizationId) on the Zed credential explicitly.","Pass options.organizationId directly to fetchZedLlmToken to bypass resolution.","Verify the account actually belongs to an organization by inspecting the /client/users/me response and use the correct id field.","Check resolveZedOrganizationId against your stored userInfo shape — normalizeOrganizationId accepts string, [id], or {id}; other shapes fail."],"exampleFix":"// before\nawait fetchZedLlmToken(credentials); // no org anywhere\n// after\nawait fetchZedLlmToken(credentials, { organizationId: \"org_abc123\" });","handlingStrategy":"validation","validationCode":"const orgId = credentials?.providerSpecificData?.organizationId\n  || credentials?.providerSpecificData?.defaultOrganizationId;\nif (!orgId) {\n  // resolve from /client/users/me first or surface org-picker UI before calling fetchZedLlmToken\n}\n","typeGuard":"const hasOrg = (c) => Boolean(c?.providerSpecificData?.organizationId || c?.providerSpecificData?.defaultOrganizationId);","tryCatchPattern":"try {\n  const token = await fetchZedLlmToken(credentials, options);\n} catch (e) {\n  if (e.message === \"No Zed organization selected\") {\n    // show organization picker / verify account membership\n  } else throw e;\n}","preventionTips":["Persist organizationId in providerSpecificData right after OAuth sign-in.","Verify the account belongs to at least one organization before enabling the Zed provider.","Handle the org-picker UI flow when userInfo contains multiple/zero orgs."],"tags":["zed","oauth","configuration","organization"],"backgroundTag":"missing-configuration","analyzedSha":"90b52e06ffd666b7929554211474d01588f6b1f8","analyzedAt":"2026-08-30T21:05:45.952Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}