mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-27 06:13:07 +00:00
fix(cli): send pi's session id from lite pi so sessions group and stick (#47700)
* fix(cli): send pi's session id from lite pi so sessions group and stick * docs(cli): drop the provider_block docstring lines the README already covers * docs(cli): note the session id format the proxy reads for lite pi
This commit is contained in:
parent
8fe0a7358e
commit
8d6b8dab3d
3 changed files with 10 additions and 3 deletions
|
|
@ -494,7 +494,7 @@ Each command resolves your LiteLLM key (logging in via SSO when none is stored a
|
|||
|
||||
The right variables are picked per agent. Claude Code gets `ANTHROPIC_BASE_URL` (the proxy root, so it appends `/v1/messages`) and `ANTHROPIC_AUTH_TOKEN`, with any stray `ANTHROPIC_API_KEY` cleared so the proxy token wins, and `ENABLE_TOOL_SEARCH=true` (unless you already set it) so Claude Code keeps tool search on even though the base URL is a proxy rather than a first-party Anthropic host. It also gets `CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY=1` (again unless you already set it) so Claude Code v2.1.129+ fills its `/model` picker from the proxy's `/v1/models`; Claude Code only lists entries whose id contains `claude` or `anthropic`, so the proxy lists every other group to Claude Code as `claude-router-<UTF-8 hex of the group name>` and marks a group whose input window reaches 1M with `[1m]`, and a request on such an id is served by the group. Older Claude Code versions ignore the variable. Export it as `0` to turn discovery off. Codex and OpenCode get `OPENAI_BASE_URL` (the proxy plus `/v1`) and `OPENAI_API_KEY`. Codex ignores `OPENAI_BASE_URL`, so it is additionally pointed at the proxy through a custom provider passed as `-c` config overrides (HTTP/SSE Responses transport, since the proxy does not speak the Responses WebSocket protocol). OpenCode additionally gets `OPENCODE_CONFIG_CONTENT` holding a generated `litellm` provider (`@ai-sdk/openai-compatible`, the proxy `/v1` URL, `{env:OPENAI_API_KEY}`) with one model entry per chat model your key can see on `/v1/models`, so its model picker mirrors the proxy without a hand-maintained `opencode.json`; OpenCode merges that over your own config files, and if you already export `OPENCODE_CONFIG_CONTENT` yours is left alone. When the list cannot be fetched, `lite opencode` says so on stderr and launches anyway. Codex gets the same list as a catalog file, `$CODEX_HOME/litellm-models.json` (default `~/.codex/`), passed as `-c model_catalog_json=<path>` so `/model` lists exactly the proxy's chat models; a proxy model the installed Codex already knows (`gpt-5.5`, say) keeps that Codex's own entry, reasoning levels and prompt included, and only its place in the picker comes from the proxy, while a model Codex does not know gets the plain entry Codex uses for an unknown `-m` slug. Before launching, `lite codex` asks the installed Codex for its own list and then has it read the written file back (both through `codex debug models`), and when the fetch, either of those or the write fails (Codex releases older than 0.130 have no such command) it says so on stderr and launches with Codex's built-in catalog, leaving a rejected file in place.
|
||||
|
||||
pi ignores base-URL environment variables entirely, so `lite pi` (kept out of the `lite --help` command listing for now, but fully functional) wires it up differently: before handoff it fetches the models your key can use from the proxy's `/v1/models` (plus each model's context window and output cap from `/model_group/info`, when available) and syncs them into a `litellm` provider entry in pi's `~/.pi/agent/models.json` (honoring `PI_CODING_AGENT_DIR`), then starts pi on that provider's first model via an injected `--model litellm/<id>`. Only that one provider entry is rewritten; the rest of the file, including any other custom providers, is left alone. The entry references the key as `$LITELLM_PROXY_API_KEY`, which the wrapper exports for the session, so the token itself never lands on disk and plain `pi` outside the wrapper simply shows the litellm models as unavailable. Your own flags come after the injected pin, so `lite pi --model litellm/<other-id>` wins, and inside the TUI the `/model` picker lists every synced litellm model.
|
||||
pi ignores base-URL environment variables entirely, so `lite pi` (kept out of the `lite --help` command listing for now, but fully functional) wires it up differently: before handoff it fetches the models your key can use from the proxy's `/v1/models` (plus each model's context window and output cap from `/model_group/info`, when available) and syncs them into a `litellm` provider entry in pi's `~/.pi/agent/models.json` (honoring `PI_CODING_AGENT_DIR`), then starts pi on that provider's first model via an injected `--model litellm/<id>`. Only that one provider entry is rewritten; the rest of the file, including any other custom providers, is left alone. The entry references the key as `$LITELLM_PROXY_API_KEY`, which the wrapper exports for the session, so the token itself never lands on disk and plain `pi` outside the wrapper simply shows the litellm models as unavailable. The entry also turns on pi's session header (`x-session-id`, sent by pi 0.80.7 and later), so every chat turn of one pi session shares one session id in the logs and sticks to one deployment when session affinity is on. A custom `pi --session-id` must be at least 8 letters, digits, `_`, or `-` for the proxy to read it. Your own flags come after the injected pin, so `lite pi --model litellm/<other-id>` wins, and inside the TUI the `/model` picker lists every synced litellm model.
|
||||
|
||||
Options (these belong to the wrapper, so put them before the agent's own flags):
|
||||
|
||||
|
|
|
|||
|
|
@ -191,7 +191,7 @@ def provider_block(
|
|||
Real contextWindow/maxTokens matter: pi otherwise assumes 128k/16384, which
|
||||
breaks compaction thresholds and over-asks models with smaller output caps.
|
||||
pi sniffs compat from the base URL, and one gateway URL fronts models with
|
||||
different capabilities, so both flags are pinned off.
|
||||
different capabilities, so the store and long-cache flags are pinned off.
|
||||
"""
|
||||
return {
|
||||
"baseUrl": base_url.rstrip("/") + "/v1",
|
||||
|
|
@ -199,6 +199,8 @@ def provider_block(
|
|||
"compat": {
|
||||
"supportsStore": False,
|
||||
"supportsLongCacheRetention": False,
|
||||
"sendSessionAffinityHeaders": True,
|
||||
"sessionAffinityFormat": "openrouter",
|
||||
},
|
||||
"apiKey": f"${LITELLM_PROXY_API_KEY_ENV}",
|
||||
"models": [_model_entry(model_id, limits) for model_id in model_ids],
|
||||
|
|
|
|||
|
|
@ -195,7 +195,12 @@ class TestProviderBlock:
|
|||
assert block == {
|
||||
"baseUrl": "http://localhost:4000/v1",
|
||||
"api": "openai-completions",
|
||||
"compat": {"supportsStore": False, "supportsLongCacheRetention": False},
|
||||
"compat": {
|
||||
"supportsStore": False,
|
||||
"supportsLongCacheRetention": False,
|
||||
"sendSessionAffinityHeaders": True,
|
||||
"sessionAffinityFormat": "openrouter",
|
||||
},
|
||||
"apiKey": "$LITELLM_PROXY_API_KEY",
|
||||
"models": [{"id": "m-1"}, {"id": "m-2"}],
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue