Skip to content

feat(openai_api_compatible): support dynamic extra_headers model parameter - #3869

Open
Souravrajvi0 wants to merge 4 commits into
langgenius:mainfrom
Souravrajvi0:feat/openai-compat-extra-headers-069c
Open

feat(openai_api_compatible): support dynamic extra_headers model parameter#3869
Souravrajvi0 wants to merge 4 commits into
langgenius:mainfrom
Souravrajvi0:feat/openai-compat-extra-headers-069c

Conversation

@Souravrajvi0

@Souravrajvi0 Souravrajvi0 commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #3865

Adds an extra_headers model parameter to the OpenAI API Compatible LLM provider so callers can send per-invocation HTTP headers with Dify-resolved variables.

Use case

OpenCode Go requires a stable session header per conversation:

{
  "x-opencode-session": "{{#sys.conversation_id#}}"
}

Dify resolves workflow/system variables in model parameters at invocation time; this change forwards the resolved headers to the underlying OpenAI-compatible request.

Changes

  • Expose extra_headers (JSON string) in the LLM model parameter schema
  • Parse and merge model-parameter headers with any credential-level extra_headers
  • Forward merged headers on both Chat Completions (requests) and Responses API (OpenAI client) paths
  • Add regression tests (8 passing)

Test plan

  • uv run pytest models/openai_api_compatible/tests/test_extra_headers.py
  • Configure OpenAI API Compatible model with extra_headers using {{#sys.conversation_id#}}

…meter

Expose an extra_headers JSON model parameter on the OpenAI API Compatible
LLM provider so callers can send per-invocation HTTP headers with resolved
Dify variables (e.g. x-opencode-session from sys.conversation_id).

Merges model-parameter headers with any credential-level extra_headers and
forwards them to both Chat Completions and Responses API request paths.

Fixes langgenius#3865
@crazywoola
crazywoola had a problem deploying to models/openai_api_compatible September 11, 2026 14:24 — with GitHub Actions Failure
@crazywoola
crazywoola self-requested a review September 12, 2026 03:28
@crazywoola
crazywoola had a problem deploying to models/openai_api_compatible September 14, 2026 01:30 — with GitHub Actions Failure
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.

Feature Request: Reconsider dynamic custom request headers in OpenAI API Compatible provider — now required by OpenCode Go

2 participants