Skip to content

fix: use Anthropic SDK for comment classification instead of hardcoded API URL#1154

Open
the-real-mathew-moon wants to merge 2 commits intoanthropics:mainfrom
the-real-mathew-moon:fix/use-sdk-for-classification-api-calls
Open

fix: use Anthropic SDK for comment classification instead of hardcoded API URL#1154
the-real-mathew-moon wants to merge 2 commits intoanthropics:mainfrom
the-real-mathew-moon:fix/use-sdk-for-classification-api-calls

Conversation

@the-real-mathew-moon
Copy link
Copy Markdown

Summary

  • Replace raw fetch() call to hardcoded https://api.anthropic.com/v1/messages in post-buffered-inline-comments.ts with the official @anthropic-ai/sdk client
  • The SDK automatically respects ANTHROPIC_API_KEY and ANTHROPIC_BASE_URL environment variables, fixing the issue for users routing traffic through a proxy or custom gateway
  • Pass ANTHROPIC_BASE_URL env var to the post-buffered-inline-comments step in action.yml

Motivation

The classifyComments() function used a hardcoded https://api.anthropic.com/v1/messages URL via raw fetch(), bypassing ANTHROPIC_BASE_URL. Users who set this env var to route traffic through an LLM gateway or proxy found that the comment classification step always hit api.anthropic.com directly.

Changes

File Change
src/entrypoints/post-buffered-inline-comments.ts Replace raw fetch() with new Anthropic().messages.create()
action.yml Pass ANTHROPIC_BASE_URL to the post-buffered-inline-comments step
package.json / bun.lock Add @anthropic-ai/sdk dependency

Note on src/github/token.ts

The other hardcoded api.anthropic.com usage in token.ts (/api/github/github-app-token-exchange) is a proprietary Anthropic infrastructure endpoint for OIDC token exchange — not a standard Messages API call. It cannot be replaced with an SDK call, and making it respect ANTHROPIC_BASE_URL could break functionality (e.g., Bedrock/Vertex proxies wouldn't have this endpoint).

Test plan

  • bun run typecheck passes
  • bun run format:check passes
  • bun test — all 653 tests pass

Generated with Claude Code

the-real-mathew-moon and others added 2 commits April 2, 2026 17:56
…ification

The `classifyComments()` function in `post-buffered-inline-comments.ts`
was using a raw `fetch()` call to a hardcoded `https://api.anthropic.com/v1/messages`
URL. This ignores `ANTHROPIC_BASE_URL`, which breaks users routing traffic
through a proxy or custom gateway.

Replace the raw fetch with the official `@anthropic-ai/sdk` client, which
automatically reads `ANTHROPIC_API_KEY` and `ANTHROPIC_BASE_URL` from the
environment. Also pass `ANTHROPIC_BASE_URL` into the post-buffered-inline-comments
step in `action.yml` so the env var is available at runtime.

Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Code <noreply@anthropic.com>
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.

1 participant