{"record":{"id":"6580be3723c1d29c","repo":"paperclipai/paperclip","slug":"opencode-returned-no-models-run-opencode-models","errorCode":null,"errorMessage":"OpenCode returned no models. Run `opencode models` and verify provider auth.","messagePattern":"OpenCode returned no models\\. Run `opencode models` and verify provider auth\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/adapters/opencode-local/src/server/models.ts","lineNumber":209,"sourceCode":"\n  // When the caller opts into OPENCODE_ALLOW_ALL_MODELS, OpenCode accepts any\n  // provider/model at run time (e.g. gateway-routed models that never appear in\n  // `opencode models` output). Honour that by skipping the availability probe;\n  // we still enforce the provider/model format above and do not second-guess\n  // the configured model. Prefer the explicit run env, then the process env.\n  const env = normalizeEnv(input.env);\n  if (isTruthyEnvFlag(env.OPENCODE_ALLOW_ALL_MODELS ?? process.env.OPENCODE_ALLOW_ALL_MODELS)) {\n    return [{ id: model, label: model }];\n  }\n\n  const models = await discoverOpenCodeModelsCached({\n    command: input.command,\n    cwd: input.cwd,\n    env: input.env,\n  });\n\n  if (models.length === 0) {\n    throw new Error(\"OpenCode returned no models. Run `opencode models` and verify provider auth.\");\n  }\n\n  if (!models.some((entry) => entry.id === model)) {\n    const sample = models.slice(0, 12).map((entry) => entry.id).join(\", \");\n    throw new Error(\n      `Configured OpenCode model is unavailable: ${model}. Available models: ${sample}${models.length > 12 ? \", ...\" : \"\"}`,\n    );\n  }\n\n  return models;\n}\n\nexport async function listOpenCodeModels(): Promise<AdapterModel[]> {\n  try {\n    return await discoverOpenCodeModelsCached();\n  } catch {\n    return [];\n  }","sourceCodeStart":191,"sourceCodeEnd":227,"githubUrl":"https://github.com/paperclipai/paperclip/blob/67001ec6eb96ae601aa27bc91d9b2415d665334a/packages/adapters/opencode-local/src/server/models.ts#L191-L227","documentation":"Thrown by ensureOpenCodeModelConfiguredAndAvailable (LOCAL, models.ts) when discovery completes but returns zero models, after the OPENCODE_ALLOW_ALL_MODELS bypass was not set. It tells the operator to run `opencode models` and verify provider auth, because the binary ran but enumerated nothing.","triggerScenarios":"discoverOpenCodeModelsCached returns [] and env.OPENCODE_ALLOW_ALL_MODELS is not truthy. The model id already passed requireOpenCodeModelId (format ok); the failure is that no provider serves any model.","commonSituations":"opencode installed and runs but no provider API key is configured; the provider env vars are present but invalid; opencode config has all providers disabled.","solutions":["Run `opencode models` locally and confirm it lists provider/model lines.","Set a valid provider API key in the env passed to discovery (e.g. ANTHROPIC_API_KEY / OPENAI_API_KEY).","Run `opencode login` for the relevant provider.","If the model is gateway-routed and won't appear in the list, set OPENCODE_ALLOW_ALL_MODELS=true to bypass the availability check."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"const allowAll = isTruthyEnvFlag(normalizeEnv(input.env).OPENCODE_ALLOW_ALL_MODELS ?? process.env.OPENCODE_ALLOW_ALL_MODELS);\nif (!allowAll) {\n  // ensure at least one provider API key is set before calling ensureOpenCodeModelConfiguredAndAvailable\n}","typeGuard":null,"tryCatchPattern":"try {\n  return await ensureOpenCodeModelConfiguredAndAvailable(input);\n} catch (e) {\n  if (e instanceof Error && /OpenCode returned no models/.test(e.message)) {\n    // set provider auth or OPENCODE_ALLOW_ALL_MODELS, then retry\n  }\n  throw e;\n}","preventionTips":["Set at least one provider API key in the run env.","Run `opencode models` locally during workspace setup to catch auth gaps early.","Use OPENCODE_ALLOW_ALL_MODELS for gateway-routed models."],"tags":["opencode","models","provider-auth","discovery","configuration"],"backgroundTag":null,"analyzedSha":"67001ec6eb96ae601aa27bc91d9b2415d665334a","analyzedAt":"2026-08-12T12:05:45.408Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}