Skip to content

feat(agentic-server): GET /v1/models lists served models by id and name; /healthz reports liveness only - #2013

Open
pyramation wants to merge 2 commits into
mainfrom
feat/agentic-models-list
Open

pyramation wants to merge 2 commits into
mainfrom
feat/agentic-models-list

Conversation

@pyramation

@pyramation pyramation commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Gateway half of constructive-planning#2528: nothing listed the models a run can use, so a wrong CODE_TASK_MODEL was only discovered when the run's first model call failed.

  • GET /v1/models returns { object: 'list', data: [{ id, name }] } and nothing else. It requires X-Database-Id, the same identity a chat/embedding call carries (400 without it).
    • The list is read from each configured provider's own listing (/v1/models for openai/anthropic, /api/tags for ollama) with the gateway's key; caller headers are not forwarded.
    • id is what to send as model: the bare upstream id when resolveProvider would route it to the provider that serves it, otherwise name/id. name is the upstream display_name, else the id.
    • No provider type, base URL, key or upstream metadata (owned_by, sizes) is returned. One caveat: a name/ prefix is the registry name the operator chose, which defaults to the dialect; it appears only where a model cannot be addressed without it.
    • If a provider cannot be listed the answer is 502 { error: { message: 'the model list is unavailable' } }; the reason goes to the log only.
  • Unknown model: an upstream 404 (how every dialect answers a model it does not serve) now ends with GET /v1/models lists the models this gateway serves.
  • GET /healthz now returns { status: 'ok' } only. It previously returned the first provider's type and base URL, and it is unauthenticated: in constructive-db a tenant workload reaches it through the node gateway's model lane, which forwards any path. This is a response-shape change for anything reading provider/providerUrl from /healthz.
  • GET /v1/providers is unchanged (operator endpoint). The constructive-db PR closes the lane to it instead.

Tests: __tests__/models.test.ts (written first, 6 failing before the change): identity required, id/name shape across three dialects including the prefixed case, no provider internals in the body, 502 without the upstream reason, the unknown-model hint, and /healthz.

Not verified: against real OpenAI/Anthropic/Ollama listings (mock upstreams only).

Link to Devin session: https://app.devin.ai/sessions/cff8c5d8274c475db01e55ac47e7b519
Open in Devin Desktop: https://app.devin.ai/desktop/session/cff8c5d8274c475db01e55ac47e7b519?variant=devin
Requested by: @pyramation


🟢 Devin fixed all 2 findings · Follow Devin's work

Devin Review

@devin-ai-integration

Copy link
Copy Markdown
Contributor

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

@luxor-code-review

luxor-code-review Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Review complete. 🟡 1 medium

💬 Inline comments (1)

  • 🟡 Slash ids matching a provider name are advertised bare but routed split — models.ts:55

This PR introduces a models listing surface for the agentic server: upstream /v1/models responses (OpenAI and Anthropic shapes) are fetched per configured provider, normalized to OpenAI list format, and served with awareness of provider-prefixed vs bare ids. Unknown-model errors on /v1/chat/completions now embed a hint pointing users to /v1/models, and the healthz payload is narrowed. Tests cover listing, prefixes, and the 404 hint; the README documents the new endpoint.

Files Change
agentic/agentic-server/src/models.ts New models listing module: fetch/normalize upstream model catalogs and compute advertised (bare vs prefixed) ids per provider.
agentic/agentic-server/src/router.ts Adds the /v1/models route and appends the model-list hint to unknown-model 404 responses.
agentic/agentic-server/src/index.ts Minor wiring adjustments for the new module.
agentic/agentic-server/__tests__/models.test.ts New tests for listing normalization and id advertising.
agentic/agentic-server/__tests__/gateway.test.ts Tests for the 404 hint and endpoint behavior.
agentic/agentic-server/README.md Documents the /v1/models endpoint.

Reviewed commit: 19c3565

@luxor-code-review luxor-code-review Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adds an OpenAI-compatible /v1/models listing endpoint to the agentic gateway, with provider-scoped model discovery, a model-list hint on unknown-model 404s, and updated tests/README.

Key findings

  • 🟡 Slash ids matching a provider name are advertised bare but routed split — models.ts:55

Comment on lines +55 to +61
const routed = resolveProvider(options, id);
const bare = providers.length === 1 || providerName(routed) === providerName(provider);
const served = bare ? id : `${providerName(provider)}/${id}`;
if (seen.has(served)) return [];
seen.add(served);
return [{ id: served, name }];
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 bug · medium

Slash ids matching a provider name are advertised bare but routed split

A model id that itself contains / and whose first segment matches a provider name is advertised bare, yet a request with that id is split and relayed without its first segment. In listServedModels, resolveProvider(options, 'hosted/thing') resolves back to the same hosted provider, so bare is true and the listing shows hosted/thing (agentic/agentic-server/src/models.ts:55-56). But upstreamModel strips the prefix equal to providerName and relays only thing (agentic/agentic-server/src/transforms.ts:31-35), so the advertised id selects a nonexistent model on the upstream. Callers picking models from /v1/models fail on their first call with every run configured with such an id.

📋 Prompt for AI Agents

In agentic/agentic-server/src/models.ts around lines 54-61, fix the bare/prefix decision in listServedModels: if the upstream id contains '/' and its first segment matches a registered provider name or type (the same test resolveProvider's split at src/providers.ts:46-52 uses), advertise the prefixed form ${providerName(provider)}/${id} instead of the bare id, because upstreamModel (src/transforms.ts:29-36) will strip the matching prefix on the request path and relay the wrong model. Add a test where a provider named 'hosted' serves id 'hosted/thing' asserting the listing shows 'hosted/hosted/thing' and a chat request with that id reaches the upstream with model 'hosted/thing'.

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 2 findings. Devin automatically fixed all 2 findings.

Fixed by Devin (2)
  • Listed model IDs lose upstream namespaces — An id is listed bare only if upstreamModel leaves it unchanged; otherwise it gets the provider prefix. Test added.
  • Model discovery drops later Anthropic pages — The listing now follows has_more/last_id with after_id until the last page. Test added.

View findings in Devin Review · Follow Devin's work

Devin Review

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