feat(azure_openai): attach Dify app_id as request metadata (opt-in)#3233
Draft
mas-sakai wants to merge 6 commits into
Draft
feat(azure_openai): attach Dify app_id as request metadata (opt-in)#3233mas-sakai wants to merge 6 commits into
mas-sakai wants to merge 6 commits into
Conversation
Refs: langgenius/dify#35772, langgenius/dify-plugin-sdks#311 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…sponses routes Refs: langgenius/dify#35772, langgenius/dify-plugin-sdks#311 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Refs: langgenius/dify#35772, langgenius/dify-plugin-sdks#311 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Refs: langgenius/dify#35772, langgenius/dify-plugin-sdks#311 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Refs: langgenius/dify#35772, langgenius/dify-plugin-sdks#311 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Code Review
This pull request introduces support for attaching Dify metadata (dify_app_id and dify_source) to Azure OpenAI Chat Completions and Responses API requests. This feature is opt-in and can be enabled via the new enable_request_metadata configuration option. The implementation includes helper functions for metadata normalization and injection, integrated into the LLM generation flows, along with corresponding unit tests and dependency updates. Feedback on the changes suggests avoiding in-place mutation of the existing metadata dictionary to prevent side effects, and adding an explicit check for None in the normalization helper to avoid converting it to the literal string 'None'.
…in normalize per review Per gemini-code-assist on langgenius#3233. Aligns 4 plugins on the same 'no side effects on existing args' principle. Refs: langgenius/dify#35772, langgenius/dify-plugin-sdks#311 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
mas-sakai
added a commit
to mas-sakai/dify-official-plugins
that referenced
this pull request
May 31, 2026
…malize per review Per gemini-code-assist on langgenius#3233. Aligns 4 plugins on the same 'no side effects on existing args' principle. Refs: langgenius/dify#35772, langgenius/dify-plugin-sdks#311 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
mas-sakai
added a commit
to mas-sakai/dify-official-plugins
that referenced
this pull request
May 31, 2026
…rmalize per review Per gemini-code-assist on langgenius#3233. Aligns 4 plugins on the same 'no side effects on existing args' principle. Refs: langgenius/dify#35772, langgenius/dify-plugin-sdks#311 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
mas-sakai
added a commit
to mas-sakai/dify-official-plugins
that referenced
this pull request
May 31, 2026
…malize per review Per gemini-code-assist on langgenius#3233. Aligns 4 plugins on the same 'no side effects on existing args' principle. Refs: langgenius/dify#35772, langgenius/dify-plugin-sdks#311 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds opt-in support for attaching the Dify
app_idas Azure OpenAI request metadata, so per-app usage can be filtered in Stored Completions.When the new
enable_request_metadatacredential is set toenabled, the plugin readsapp_idfrom the current Dify session (viaget_current_session()from the SDK) and attaches{dify_app_id, dify_source}as themetadatafield on both the Chat Completions route (chat.completions.create) and the Responses route (responses.create). The default isdisabled, so behavior is unchanged unless the operator opts in.This is the Azure OpenAI counterpart of the same feature already shipped for Vertex AI (#3168), Bedrock (#3201), and OpenAI (#3203). The responsibility split mirrors those plugins:
generateContentrequestMetadataon Conversemetadataon Chat / Responsesmetadataon Chat / ResponsesDesign note:
storeis deliberately not setThe plugin does not set
store=trueon requests. Whether metadata persists and surfaces depends entirely on the Stored Completions setting of the Azure OpenAI resource, which the resource owner controls. Settingstorefrom inside the plugin would change persistence behavior as a side effect of a telemetry opt-in — same responsibility split as OpenAI (account-level Stored Completions), Bedrock (CloudWatch), and Vertex (billing export). The credential's help text inprovider/azure_openai.yamldocuments this expectation in both English and Simplified Chinese.See: https://learn.microsoft.com/en-us/azure/ai-foundry/openai/how-to/stored-completions
Related:
Note
Draft / dependency.
pyproject.tomltemporarily pinsdify_pluginto the fork branchryuta-kobayashi-ug/dify-plugin-sdks@feat/pass-session-to-model-pluginsbecause it carries theget_current_session()API used here (langgenius/dify-plugin-sdks#313). The pin will revert to a versioneddify_pluginspec once that SDK change merges and a release ships.Change Type
Screenshots / Videos
dify_app_idanddify_source, enabling per-app filtering.End-to-end screenshots will be added once the dependent SDK change (#313) ships and a Dify deployment can be exercised against a live Azure OpenAI resource with Stored Completions enabled.
LLM Plugin Checklist
Areas affected by this change
The change is additive and behind a credential that defaults to
disabled. No existing message flow, tool, multimodal, structured-output, or token-accounting code path is altered. Only_chat_generate(Chat Completions route) and_chat_generate_with_responses(Responses route) gain a one-line opt-in hook that mutates the request kwargs immediately before the Azure OpenAI client call. The legacy_generatecompletions route is intentionally left untouched.🤖 Generated with Claude Code