Skip to content

Say at boot when the key cannot call the configured model - #782

Merged
guidovizoso merged 2 commits into
mainfrom
feat/warn-unavailable-model
Oct 13, 2026
Merged

guidovizoso merged 2 commits into
mainfrom
feat/warn-unavailable-model

Conversation

@guidovizoso

Copy link
Copy Markdown
Collaborator

Problem

A key without access to the tenant package's default_model (gpt-5.6-terra) passes every start-up check. The first time anyone finds out is when a Bot runs and the person who sent the message sees:

The model gpt-5.6-terra does not exist or you do not have access to it.

We hit this deploying on EKS: the OpenAI key was a project key whose project didn't allow that model.

Fix

At start-up the server reads the provider's single-model endpoint once, with the same key resolveModelApiKey would give a Bot (the stored credential, else OPENAI_API_KEY / ANTHROPIC_API_KEY):

answer logs
2xx nothing
404 model-unavailable: model + fix (key access, or default_model in model.yaml)
401 / 403 model-credential-rejected
anything else, or unreachable model-check-unreadable

What it deliberately leaves alone:

  • Endpoints set by OPENAI_BASE_URL / ANTHROPIC_BASE_URL. OpenAI-compatible servers often have no single-model lookup, so a 404 there would mean nothing.
  • No key configured yet, since an admin may be about to add one.

It never logs the key and never delays start-up (5 s timeout, fire-and-forget).

Tests

model-availability-check.test.ts, 11 tests:

  • each outcome
  • the exact URL and headers for OpenAI and Anthropic
  • the 404 line contains the model and not the key
  • a custom base URL is never fetched
  • no key, nothing fetched
  • a network error is reported and doesn't throw

tsc and biome are clean.

Not run against the live API from this branch. I couldn't reach the stored key when I tried. The 404-for-no-access behaviour matches what we saw from OpenAI with that key (the model was absent from /v1/models, and calls to it returned the "does not exist or you do not have access" error), but a reviewer with an OpenAI key could confirm it with one curl /v1/models/<id>.

A project key without access to the tenant package's default_model
passed every start-up check and failed at the first message, as "The
model `...` does not exist or you do not have access to it", in front of
whoever sent it. Found deploying on EKS with a key whose project did not
allow gpt-5.6-terra.

The server now reads the provider's single-model endpoint once at boot,
with the key resolveModelApiKey would hand a Bot, and logs
model-unavailable (404) with the model and the fix,
model-credential-rejected (401/403), or model-check-unreadable. It does
not ask an OPENAI_BASE_URL or ANTHROPIC_BASE_URL endpoint, where a
single-model lookup often does not exist and a 404 would mean nothing,
says nothing while no key is configured, never logs the key, and never
delays start-up.
@guidovizoso
guidovizoso merged commit cae4b6b into main Oct 13, 2026
18 checks passed
@guidovizoso
guidovizoso deleted the feat/warn-unavailable-model branch October 13, 2026 13:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant