Skip to content

feat: expose api_base on Ollama provider metadata schema#522

Open
paultancre-bt wants to merge 2 commits intomainfrom
expose-ollama-api-base
Open

feat: expose api_base on Ollama provider metadata schema#522
paultancre-bt wants to merge 2 commits intomainfrom
expose-ollama-api-base

Conversation

@paultancre-bt
Copy link
Copy Markdown

Add a typed api_base field to the Ollama provider's metadata so it can be customized in the AI providers form (e.g. to point at a self-hosted or tunnelled Ollama instance instead of the default http://127.0.0.1:11434/v1).

The proxy already honors secret.metadata.api_base generically at runtime, so this is a schema-only change. It mirrors the existing MistralMetadataSchema shape:

  • Promote ollama from the bulk z.enum to its own discriminated union arm with OllamaMetadataSchema metadata.
  • OllamaMetadataSchema is BaseMetadataSchema plus an optional api_base (allows valid URL, empty string, null, or undefined to preserve the default).

Existing Ollama secrets continue to validate (the new schema is a strict superset), so no migration is required.

Add a typed `api_base` field to the Ollama provider's metadata so it
can be customized in the AI providers form (e.g. to point at a
self-hosted or tunnelled Ollama instance instead of the default
`http://127.0.0.1:11434/v1`).

The proxy already honors `secret.metadata.api_base` generically at
runtime, so this is a schema-only change. It mirrors the existing
`MistralMetadataSchema` shape:

- Promote `ollama` from the bulk `z.enum` to its own discriminated
  union arm with `OllamaMetadataSchema` metadata.
- `OllamaMetadataSchema` is `BaseMetadataSchema` plus an optional
  `api_base` (allows valid URL, empty string, null, or undefined to
  preserve the default).

Existing Ollama secrets continue to validate (the new schema is a
strict superset), so no migration is required.
@vercel
Copy link
Copy Markdown

vercel Bot commented May 5, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
ai-proxy Ready Ready Preview, Comment May 5, 2026 11:51pm

Request Review

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2a5f98e0ff

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "Codex (@codex) review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "Codex (@codex) address that feedback".

Comment thread packages/proxy/schema/secrets.ts Outdated

export const OllamaMetadataSchema = BaseMetadataSchema.merge(
z.object({
api_base: z.union([z.string().url(), z.string().length(0)]).nullish(),
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve passthrough Ollama api_base values

For existing Ollama secrets that already have a non-string or otherwise non-URL metadata.api_base, this new provider-specific arm rejects the secret where the old BaseMetadataSchema.passthrough() arm accepted it and the proxy runtime would ignore non-string values and fall back to the default base URL. The edge loader parses every fetched secret with APISecretSchema.parse (packages/proxy/edge/index.ts lines 246 and 251), so one such stored Ollama secret can now make the secret list fail to load instead of preserving the previous fallback behavior.

Useful? React with 👍 / 👎.

Address Codex review on #522. The new `OllamaMetadataSchema` arm tightens
validation on `metadata.api_base` (must be a valid URL, empty string,
null, or undefined), where the previous bulk-enum arm used
`BaseMetadataSchema.passthrough()` and silently accepted any value. The
edge loader parses every fetched secret with `APISecretSchema.parse`, so
a single stored Ollama secret with a non-URL/non-string `api_base` (e.g.
`"localhost"`, a number, or a bool from a legacy direct API call) would
throw and break the whole secret list lookup, instead of falling through
to the runtime's existing `typeof api_base === "string"` check that uses
the default base URL.

Add `.catch(undefined)` to `OllamaMetadataSchema.api_base` so invalid
stored values silently coerce to `undefined`, exactly matching the prior
"ignore and use default" semantics. Form input still surfaces validation
errors via `zodResolver` in the AI providers form, since the form parses
fresh user input separately.

Includes a regression test in `APISecretSchema compatibility` covering
invalid strings, bare hostnames, numbers, booleans, and objects.

Co-authored-by: Cursor <cursoragent@cursor.com>
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.

2 participants