Skip to content

claude: authenticate gateway model discovery - #362

Open
andy-xu-db wants to merge 7 commits into
mainfrom
claude/gateway-model-discovery-auth
Open

claude: authenticate gateway model discovery#362
andy-xu-db wants to merge 7 commits into
mainfrom
claude/gateway-model-discovery-auth

Conversation

@andy-xu-db

@andy-xu-db andy-xu-db commented Aug 20, 2026

Copy link
Copy Markdown
Collaborator

Summary

Set the gateway URL, mode, and auth token in the process environment before Claude starts.

Claude Code checks these values before settings-based environment variables and apiKeyHelper resolve. Without them, it skips GET /anthropic/v1/models.

Relayed launches are unchanged.

This PR is independent from #347 and based directly on main.

Testing

  • pytest tests/test_agent_claude.py (100 passed)
  • Ruff

This pull request and its description were written by Isaac.

@andy-xu-db
andy-xu-db force-pushed the claude/gateway-model-discovery-auth branch from befa707 to 176995c Compare August 20, 2026 19:06
@andy-xu-db
andy-xu-db requested a review from lilly-luo August 20, 2026 19:54
Comment thread src/ucode/agents/claude.py Outdated


def _launch_gateway(state: dict, binary: str, tool_args: list[str]) -> None:
from ucode.gateway_proxy import AUTHORIZATION_HEADER, start_proxy

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can this be at the top of the file instead

Comment thread src/ucode/agents/claude.py
Comment thread src/ucode/gateway_proxy.py Outdated
# near-expiry one cached from an earlier CLI call. Raises if auth is dead
# (surfaced by the caller at launch, before Claude Code starts).
self._refresh(force=True)
self._refresh()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this changing

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested with relayed auth and it works without any issues.

Comment thread src/ucode/gateway_proxy.py
Comment thread src/ucode/gateway_proxy.py Outdated
token = get_databricks_token(self._workspace, self._profile, force_refresh=force)
def _refresh(self) -> None:
"""Force-mint a token and record its expiry."""
token = get_databricks_token(self._workspace, self._profile, force_refresh=True)

@lilly-luo lilly-luo Aug 21, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are we changing to always force refresh? this is altering the existing behavior, for ex line 154 in the original code did not force a refresh

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We force refresh because a normal token request may return the same nearly expired cached token. Otherwise the refresh would trigger once the current token errors which could cause some queries to fail.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants