Skip to content

feat(ai-anthropic, ai-openai): support custom HTTP headers for custom model endpoints - #17907

Open
safisa wants to merge 2 commits into
eclipse-theia:masterfrom
safisa:feat/ai-custom-model-headers
Open

feat(ai-anthropic, ai-openai): support custom HTTP headers for custom model endpoints#17907
safisa wants to merge 2 commits into
eclipse-theia:masterfrom
safisa:feat/ai-custom-model-headers

Conversation

@safisa

@safisa safisa commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

What it does

Adds an optional headers map to custom model entries for ai-anthropic and ai-openai, sent with every request to that endpoint.

Fixes #17906

Custom model entries can only configure url and apiKey today. Deployments that route LLM traffic through a gateway in front of the vendor API commonly require additional headers for audit, attribution or routing, and reject requests that omit them — the only workaround being a reverse proxy that injects them.

"ai-features.anthropicCustom.customAnthropicModels": [{
    "model": "...",
    "url": "https://llm-gateway.internal/v1",
    "apiKey": "...",
    "headers": { "X-Audit-User-Type": "service", "X-Audit-User-Name": "theia" }
}]

The map is passed to the SDK clients as defaultHeaders, so it also covers the Anthropic /v1/models lookup that resolves model metadata — a gateway enforcing the headers rejects that request too, which otherwise degrades the model's capabilities silently.

Values are resolved through a shared resolveCustomModelHeaders helper in ai-core: preferences are user-authored JSON, so entries with a non-string value are dropped, and undefined is returned when nothing usable remains, leaving the default request headers untouched.

How to test

  1. Configure a custom Anthropic or OpenAI model whose url points at a local endpoint that logs the headers it receives, and add a headers entry.
  2. Send a chat message — the configured headers are on the request; without a headers entry the request is unchanged.
  3. Edit a header value in settings while the app is running — the next request carries the new value, no reload needed.
  4. npx mocha packages/ai-core/lib/common/language-model.spec.js covers resolveCustomModelHeaders.

Verified against a local HTTP server standing in for a gateway: the headers are present on /v1/messages and /v1/chat/completions for both providers through the full request() path, and absent when not configured.

Follow-ups

Only static per-model values are in scope here. Per-request or per-user header values (e.g. attributing a request to the signed-in user) would need request-scoped plumbing through the language model request pipeline, and are left out deliberately.

Breaking changes

  • This PR introduces breaking changes and requires careful review. If yes, the breaking changes section in the changelog has been updated.

The new headers field and the widened constructors are optional, so existing adopters are unaffected.

Attribution

Contributed on behalf of K2view

Review checklist

Reminder for reviewers

@github-project-automation github-project-automation Bot moved this to Waiting on reviewers in PR Backlog Aug 10, 2026
@ndoschek
ndoschek requested a review from eneufeld August 10, 2026 16:49
@safisa
safisa force-pushed the feat/ai-custom-model-headers branch from 1ad8c6c to cf137df Compare August 19, 2026 08:21
@safisa
safisa force-pushed the feat/ai-custom-model-headers branch from cf137df to f4cb675 Compare August 27, 2026 21:35
… model endpoints

Custom model entries can only configure 'url' and 'apiKey', so there is no
way to send additional HTTP headers to the endpoint. Deployments that route
LLM traffic through a gateway in front of the vendor API commonly require
extra headers for audit, attribution or routing, and reject requests that
omit them. The only workaround is a reverse proxy that injects them.

Add an optional 'headers' map to the custom model preference entries. The
headers are passed to the SDK clients as 'defaultHeaders', so they are sent
with every request to that endpoint, including the Anthropic /v1/models
lookup which resolves model metadata.

Header values are resolved by the shared resolveCustomModelHeaders helper,
which drops non-string entries since preferences are user-authored JSON, and
returns undefined when nothing usable remains so default headers stay
untouched.

Resolves eclipse-theiaGH-17906

Signed-off-by: safi <safi@k2view.com>
Signed-off-by: safi <safi@k2view.com>
@safisa
safisa force-pushed the feat/ai-custom-model-headers branch from f4cb675 to 4bc4423 Compare September 2, 2026 12:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Waiting on reviewers

Development

Successfully merging this pull request may close these issues.

Support custom HTTP headers for custom AI model endpoints

1 participant