feat: support client-driven model selection in ai-proxy-multi via `models` request body field
メンテナーはふだん 2 日以内に返信
まだ誰も着手していません。
- #13084 @kjprice による — マージされずにクローズ
評価
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 初心者へのやさしさ
- 45/100
- issue の種類
- 機能追加
- 明瞭さ
- 明確に書かれている
- 活発さ
- 静か
- 技術スタック
- lua
調査の方向性
まず ai-proxy-multi.lua と、その access-phase におけるインスタンス選択フローを読みます。upstream への転送前にリクエストボディと設定済みインスタンスがどのように処理されるかを追跡し、opt-in の順序、文字列およびオブジェクトのマッチング、マッチしないエントリ、モデルの除去、フォールバック動作に対するテストを定義します。デフォルトでは引き続きサーバー主導であり、有効化されたルートではクライアントの優先設定が尊重されれば完了です。
索引モデルが issue の本文から書いたものです。
説明
Description
Currently, ai-proxy-multi selects AI instances entirely server-side via configured priority, weight, and fallback_strategy. The client has no way to influence which model or provider handles their request, or in what order fallbacks should be attempted.
This proposal adds support for a models field in the request body, allowing clients to specify their preferred model ordering while the gateway retains full control over authentication, rate limiting, and provider configuration.
Proposed API
Clients include a models array in the chat completions request body. Each element can be:
Object form (full control):
{
"messages": [{"role": "user", "content": "Hello"}],
"models": [
{"provider": "anthropic", "model": "claude-sonnet-4-20250514"},
{"provider": "openai", "model": "gpt-4o"}
]
}
String shorthand (just model names, matched against configured instances):
{
"messages": [{"role": "user", "content": "Hello"}],
"models": ["claude-sonnet-4-20250514", "gpt-4o"]
}
Mixed:
{
"messages": [{"role": "user", "content": "Hello"}],
"models": [
{"provider": "anthropic", "model": "claude-sonnet-4-20250514"},
"gpt-4o"
]
}
Behavior
- The
modelsarray defines the client's preferred instance ordering (first element = highest priority). - Each entry is matched against the route's configured
ai-proxy-multiinstances bymodelname and optionallyprovider. - String entries match by model name only. Object entries can match by
provider+modelfor disambiguation (e.g., two providers serving the same model). - Unmatched entries are ignored (the client cannot introduce providers/models not configured on the route).
- Configured instances not referenced in
modelsare appended after the client's preferred list, in their original priority order. - The existing
fallback_strategystill applies — if the top-priority instance fails, the plugin falls back through the client-specified order, then server-configured instances. - Auth, rate limiting, and all other instance config remain server-controlled.
Configuration
A new optional boolean on the plugin config to opt-in:
plugins:
ai-proxy-multi:
allow_client_model_preference: true # default: false
instances:
- name: anthropic-primary
provider: anthropic
options:
model: claude-sonnet-4-20250514
# ...
- name: openai-fallback
provider: openai
options:
model: gpt-4o
# ...
When allow_client_model_preference is false (default), the models field is stripped from the request body and instance ordering is purely server-driven. This ensures backward compatibility.
Use Case
We're building an LLM proxy gateway where multiple teams consume AI services through a shared gateway. Different clients have different model preferences:
- Team A prefers Claude with GPT-4o fallback
- Team B prefers GPT-4o with Claude fallback
- The gateway team manages auth keys, rate limits, and provider configs centrally
Today this requires separate routes per team/preference. With client-driven model selection, a single route handles all teams while respecting their preferences.
Implementation Notes
- The matching logic would live in
ai-proxy-multi.lua, executed before instance selection in theaccessphase. - The
modelsfield should be stripped from the request body before forwarding to the upstream provider (providers don't recognize it). - String matching should be case-sensitive to match provider model naming conventions.
- When using
chashbalancer, client preference should take precedence over hash-based selection.
I'm happy to submit a PR for this feature if the approach looks good.
- 主要言語
- Lua
- スター
- 17.3k
- フォーク
- 3k
- 平均マージ
- 4日 14時間
- マージ済み PR(30日)
- 73
環境構築
このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
apache/apisix のほかの issue
-
bug: an admin key injected with ${{VAR}} that contains only digits becomes a number, so the correct key gets 401対応中かも @Ymmcc が 1 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 2 日以内に返信
-
bug(body-transformer): runtime crash when request or response body is a JSON primitive対応中かも @bhuvan-somisetty が 5 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 2 日以内に返信
-
bug: openapi-to-mcp appends a second ? to a query-suffixed path template対応中かも @lordcheng10 が 5 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 83/100
メンテナーはふだん 2 日以内に返信
-
ai-proxy forwards client `Transfer-Encoding: chunked` but sends an unchunked body (upstream 400)対応中かも @locker95 が 4 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
メンテナーはふだん 2 日以内に返信
-
As a user, I want the opa plugin to propagate trace context (traceparent) to OPA, so that OPA spans are linked to the APISIX request trace対応中かも @GitNimay が 21 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
apache/apisix#14051 · コメント 3 件 ·
メンテナーはふだん 2 日以内に返信
似ている issue
-
severity: low
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
luainkernel/lunatik#2460 ·
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
メンテナーはふだん 1 日以内に返信
-
bug
難易度 1/5 1時間未満 初心者へのやさしさ 82/100
nvim-neo-tree/neo-tree.nvim#2121 ·
メンテナーはふだん 5 日以内に返信
-
bug discord guide:04-dustwallow-marsh locale:enUS lua-error triage v0.3.6
難易度 2/5 1〜3時間 初心者へのやさしさ 64/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
NaixGames/Polycosmos#79 ·