Repository navigation
Conversation
This branch has not been deployed
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
OpenRouter now accepts
service_tieron Chat Completions (Service Tiers docs). Withservice_tier: "flex"it tries the model's flex endpoints first, which are billed at a lower rate (for exampleopenai/gpt-6-lunaflex is listed at 0.05 / 0.25 per 1M tokens vs 0.10 / 0.50 standard). The native OpenAI and Gemini plugins already expose a Flex tier (#2981); the OpenRouter plugin had no way to request it.This PR adds a Service Tier parameter (
auto|flex, defaultauto):GET https://openrouter.ai/api/v1/models/{model}/endpoints(endpoint tags ending in/flex):openai/flex):gpt-5-mini,gpt-5-nano,gpt-5.1,gpt-5.6-*,gpt-6-*,gpt-6.1-*google-ai-studio/flex,google-vertex/global/flex):gemini-2.5-*,gemini-3-flash-preview,gemini-3.1-*,gemini-3.5-flash-lite,gemini-3.7-flash,gemini-3.8-flashdeepseek-chat,gemma-4-31b-it,glm-5.2,minimax-m3get_customizable_model_schema. A model without a flex endpoint routes normally at standard rates, so the option is safe there._set_service_tier_paramssendsservice_tier: "flex"only when flex is selected.auto, empty or unknown values leave the parameter out, so default routing is unchanged.The help text states OpenRouter's fallback rule: flex only falls back to endpoints priced at or below the flex endpoint, otherwise a capacity error is returned. Without a flex endpoint the request routes normally.
Known limitation: usage cost shown in Dify still comes from the standard
pricingin each YAML, so flex savings appear on the OpenRouter invoice but not in Dify's cost numbers. This matches how the plugin already handles per-provider price differences on OpenRouter; the help text says so.Release Notes
Add a Service Tier parameter (
auto/flex) to OpenRouter models with flex endpoints and to custom models, forwardingservice_tier: "flex"so requests can use OpenRouter's lower-cost flex endpoints.Change Type
LLM Plugin Checklist
Areas affected by this change (check all that apply)
Version
versioninmanifest.yaml(0.1.12→0.1.13)dify_plugindependency unchangedTesting
pytest: 39 passed): flex forwarded,auto/ empty / unknown values dropped, YAML rules consistent, custom model schema exposes the rule,_invokesendsservice_tiernext to the existingprovider.data_collection_invokeagainst the OpenRouter API (openai/gpt-6-luna): withflexthe response reportedservice_tier: "flex", withautoit reporteddefaultgoogle/gemini-3.8-flashandservice_tier: "flex": served by Google AI Studio on the flex tierdify plugin package(v0.6.11)🤖 Generated with Claude Code