Skip to content

Phase 2b: Anthropic API proxy with credential injection #15

Closed

Description

@james-in-a-box

Summary

Implement the Anthropic API proxy that is shown in the egg architecture diagram but not yet implemented. This is a core security feature that enables zero-credential exposure in the sandbox.

Architecture Reference

From README.md:

│  │  │ Anthropic Proxy     │◄─┼──────────┼──│ Claude Code             │
│  │  │ (credential inject) │  │  Proxy   │  │ (ANTHROPIC_BASE_URL)    │

Components to Implement

1. gateway/anthropic_credentials.py (new file)

Extract from jib's gateway-sidecar/anthropic_credentials.py:

  • AnthropicCredential dataclass (header_name, header_value)
  • AnthropicCredentialsManager class with mtime-based cache invalidation
  • Support for both API key (x-api-key) and OAuth token (Authorization: Bearer)
  • Thread-safe credential access

2. Gateway Endpoints

Endpoint Method Purpose
/v1/messages POST Anthropic API proxy with streaming SSE support
/v1/messages/count_tokens POST Token counting API proxy

3. Key Features

  • Streaming SSE support: Forward streaming responses from Anthropic API
  • Credential injection: Add API key/OAuth header before forwarding
  • Blocked tools filtering (private mode): Filter out web_search, WebSearch, web_fetch, WebFetch from tool lists
  • IP-based session lookup: Use get_session_by_ip() (from Phase 2a) to determine session mode
  • Connection pooling: Singleton httpx client for efficiency

Dependencies

  • Phase 2a must be complete (get_session_by_ip() method required)

Acceptance Criteria

  • anthropic_credentials.py extracted and adapted for egg
  • /v1/messages endpoint with streaming support
  • /v1/messages/count_tokens endpoint
  • Credential injection working (API key and OAuth)
  • Blocked tools filtering in private mode
  • IP-based session mode detection
  • Integration test with mock Anthropic API

Reference

  • jib implementation: james-in-a-box/gateway-sidecar/anthropic_credentials.py
  • jib gateway proxy code: james-in-a-box/gateway-sidecar/gateway.py (search for /v1/messages)

Authored-by: jib

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions