fix(copilot): route Claude models through Copilot's native anthropic provider - #495
Draft
larsmoan wants to merge 1 commit into
Draft
fix(copilot): route Claude models through Copilot's native anthropic provider#495larsmoan wants to merge 1 commit into
larsmoan wants to merge 1 commit into
Conversation
…provider ucode always configured Copilot CLI with COPILOT_PROVIDER_TYPE=openai, pointing even Claude models at the OpenAI-compatible MLflow gateway. That wire format has no field for an Anthropic cache_control breakpoint, so Copilot's own prompt-cache logic (confirmed present in its runtime) never ran and gateway usage data showed zero cache hits on Claude traffic. Claude models now get COPILOT_PROVIDER_TYPE=anthropic against the same native /ai-gateway/anthropic path claude.py uses, authenticated via COPILOT_PROVIDER_API_KEY (x-api-key) instead of the bearer-token var used for the openai path. Codex (gpt-5) keeps the openai provider against the MLflow gateway, since it has no native-dialect option on Copilot's side. Fixes databricks#494
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 #494.
Claude models routed through Copilot CLI get zero Anthropic prompt-cache
hits, because ucode always sets
COPILOT_PROVIDER_TYPE=openaiand pointsCopilot at the OpenAI-compatible MLflow gateway — a wire format with no field
for a
cache_controlbreakpoint — even for Claude models. Every other agentucode configures (
claude,opencode,pi) already gets Claude trafficrouted to Databricks' native
/ai-gateway/anthropicpath; Copilot did not.Copilot CLI documents (and its shipped runtime implements) a native
COPILOT_PROVIDER_TYPE=anthropicprovider — see issue #494 for theruntime-string evidence (
prompt_cache_request.rs,attemptCacheControl,ephemeral_5m_input_tokens, etc.) that this path actually insertscache_controlbreakpoints. This PR uses it.Changes
databricks.py:build_copilot_base_url(single URL) →build_copilot_base_urls(dict with
anthropicandopenaientries), same pattern asbuild_opencode_base_urls/build_pi_base_urls.build_shared_base_urls()["copilot"]is now a dict, matching the existing precedent for opencode/pi.
agents/copilot.py:render_env_overlaynow branches on whether theselected model is a Claude model (
"claude" in model.lower(), samesubstring check
databricks.pyalready uses elsewhere for this family):COPILOT_PROVIDER_TYPE=anthropic,COPILOT_PROVIDER_BASE_URL= the native anthropic gateway,COPILOT_PROVIDER_API_KEY(Copilot's native-Anthropic auth var, sent asx-api-key— same header Claude Code'sapiKeyHelperalreadyauthenticates with against this same endpoint).
COPILOT_PROVIDER_TYPE=openai,MLflow gateway,
COPILOT_PROVIDER_BEARER_TOKEN.write_tool_confignow clears whichever ofCOPILOT_PROVIDER_API_KEY/COPILOT_PROVIDER_BEARER_TOKENdoesn't applybefore writing, so switching the default model between families doesn't
leave a stale auth key in
~/.copilot/ucode.env.test_agent_copilot.pyandtest_databricks.py.Not yet verified
I don't have a live workspace handy to confirm
system.ai_gateway.usageactually shows
cache_read_input_tokens > 0for Copilot traffic after thischange — the auth-header compatibility (
x-api-keyagainst/ai-gateway/anthropic) is inferred from howclaude.pyalreadyauthenticates against the same endpoint, not directly tested against
Copilot's client. Opening as a draft for that reason — happy to run the e2e
suite (
tests/test_e2e.py::...test_launch_copilot_per_model) against a realworkspace before marking ready.
Test plan
uv run pytest tests/test_agent_copilot.py tests/test_databricks.py -quv run pytest -q(full suite; one pre-existing unrelated failure intest_e2e_user_agent.pyreproduces identically onmain)uv run ruff check .system.ai_gateway.usagefor a Copilot +Claude session against a live workspace