feat(api): pass app_id to model plugins for provider-side cost attribution#35859
Open
ryuta-kobayashi-ug wants to merge 2 commits into
Open
feat(api): pass app_id to model plugins for provider-side cost attribution#35859ryuta-kobayashi-ug wants to merge 2 commits into
ryuta-kobayashi-ug wants to merge 2 commits into
Conversation
Contributor
Pyrefly Diffbase → PR--- /tmp/pyrefly_base.txt 2026-05-06 13:52:40.434110858 +0000
+++ /tmp/pyrefly_pr.txt 2026-05-06 13:52:26.808039981 +0000
@@ -4126,33 +4126,33 @@
ERROR Argument `None` is not assignable to parameter `project` with type `str` in function `core.ops.utils.validate_project_name` [bad-argument-type]
--> tests/unit_tests/core/ops/test_utils.py:136:40
ERROR Missing required key `content` for TypedDict `MultimodalRerankInput` [bad-typed-dict-key]
- --> tests/unit_tests/core/plugin/impl/test_model_client.py:340:19
+ --> tests/unit_tests/core/plugin/impl/test_model_client.py:392:19
ERROR Missing required key `content_type` for TypedDict `MultimodalRerankInput` [bad-typed-dict-key]
- --> tests/unit_tests/core/plugin/impl/test_model_client.py:340:19
+ --> tests/unit_tests/core/plugin/impl/test_model_client.py:392:19
ERROR Key `type` is not defined in TypedDict `MultimodalRerankInput` [bad-typed-dict-key]
- --> tests/unit_tests/core/plugin/impl/test_model_client.py:340:20
+ --> tests/unit_tests/core/plugin/impl/test_model_client.py:392:20
ERROR Key `value` is not defined in TypedDict `MultimodalRerankInput` [bad-typed-dict-key]
- --> tests/unit_tests/core/plugin/impl/test_model_client.py:340:36
+ --> tests/unit_tests/core/plugin/impl/test_model_client.py:392:36
ERROR Missing required key `content` for TypedDict `MultimodalRerankInput` [bad-typed-dict-key]
- --> tests/unit_tests/core/plugin/impl/test_model_client.py:341:19
+ --> tests/unit_tests/core/plugin/impl/test_model_client.py:393:19
ERROR Missing required key `content_type` for TypedDict `MultimodalRerankInput` [bad-typed-dict-key]
- --> tests/unit_tests/core/plugin/impl/test_model_client.py:341:19
+ --> tests/unit_tests/core/plugin/impl/test_model_client.py:393:19
ERROR Key `type` is not defined in TypedDict `MultimodalRerankInput` [bad-typed-dict-key]
- --> tests/unit_tests/core/plugin/impl/test_model_client.py:341:20
+ --> tests/unit_tests/core/plugin/impl/test_model_client.py:393:20
ERROR Key `value` is not defined in TypedDict `MultimodalRerankInput` [bad-typed-dict-key]
- --> tests/unit_tests/core/plugin/impl/test_model_client.py:341:37
+ --> tests/unit_tests/core/plugin/impl/test_model_client.py:393:37
ERROR Missing required key `content` for TypedDict `MultimodalRerankInput` [bad-typed-dict-key]
- --> tests/unit_tests/core/plugin/impl/test_model_client.py:360:17
+ --> tests/unit_tests/core/plugin/impl/test_model_client.py:412:17
ERROR Missing required key `content_type` for TypedDict `MultimodalRerankInput` [bad-typed-dict-key]
- --> tests/unit_tests/core/plugin/impl/test_model_client.py:360:17
+ --> tests/unit_tests/core/plugin/impl/test_model_client.py:412:17
ERROR Key `type` is not defined in TypedDict `MultimodalRerankInput` [bad-typed-dict-key]
- --> tests/unit_tests/core/plugin/impl/test_model_client.py:360:18
+ --> tests/unit_tests/core/plugin/impl/test_model_client.py:412:18
ERROR Missing required key `content` for TypedDict `MultimodalRerankInput` [bad-typed-dict-key]
- --> tests/unit_tests/core/plugin/impl/test_model_client.py:361:18
+ --> tests/unit_tests/core/plugin/impl/test_model_client.py:413:18
ERROR Missing required key `content_type` for TypedDict `MultimodalRerankInput` [bad-typed-dict-key]
- --> tests/unit_tests/core/plugin/impl/test_model_client.py:361:18
+ --> tests/unit_tests/core/plugin/impl/test_model_client.py:413:18
ERROR Key `type` is not defined in TypedDict `MultimodalRerankInput` [bad-typed-dict-key]
- --> tests/unit_tests/core/plugin/impl/test_model_client.py:361:19
+ --> tests/unit_tests/core/plugin/impl/test_model_client.py:413:19
ERROR Argument `werkzeug.wrappers.request.Request` is not assignable to parameter `request` with type `flask.wrappers.Request` in function `core.plugin.impl.trigger.PluginTriggerClient.invoke_trigger_event` [bad-argument-type]
--> tests/unit_tests/core/plugin/impl/test_trigger_client.py:126:21
ERROR Argument `werkzeug.wrappers.request.Request` is not assignable to parameter `request` with type `flask.wrappers.Request` in function `core.plugin.impl.trigger.PluginTriggerClient.invoke_trigger_event` [bad-argument-type]
|
15 tasks
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.
Fixes #35772
Summary
Pass
app_idto model plugins so they can tag LLM requests with the originating Dify app for provider-side cost attribution (e.g., BedrockrequestMetadata, OpenAImetadata, Vertex AIlabels).Changes
app_context.pywithContextVar-basedget_current_app_id()/set_current_app_id()app_idin all app runners (chat, completion, agent_chat, advanced_chat, workflow) before LLM invocationPluginModelRuntime.invoke_llm()readsget_current_app_id()and passes it toPluginModelClientPluginModelClientincludesapp_idin the HTTP payload to plugin daemonapp_idisNonewhen called outside app context (RAG routing, title generation, etc.)Design
Uses
contextvars.ContextVarbecausePluginModelRuntimeis created at tenant scope (before app execution), and graphon sits between the app runner andPluginModelRuntimewith a fixed interface that cannot passapp_idas an argument.Testing
_dispatch_payloadwith/withoutapp_idapp_idcorrectlyChecklist