Skip to content

feat: add --anthropic-auth-token option for API access protection#1

Draft
Copilot wants to merge 5 commits intomasterfrom
copilot/add-anthropic-auth-token-option
Draft

feat: add --anthropic-auth-token option for API access protection#1
Copilot wants to merge 5 commits intomasterfrom
copilot/add-anthropic-auth-token-option

Conversation

Copy link
Copy Markdown

Copilot AI commented Feb 6, 2026

Adds optional authentication to the copilot-api server. When --anthropic-auth-token is set, clients must provide a matching token via x-api-key or Authorization: Bearer header. Without it, behavior is unchanged.

Changes

  • src/lib/auth-middleware.ts — New Hono middleware with timing-safe token comparison (crypto.timingSafeEqual). Skips validation when no token is configured.
  • src/lib/state.ts — Added anthropicAuthToken to State
  • src/server.ts — Applied auth middleware globally
  • src/start.ts — Added --anthropic-auth-token CLI arg; Claude Code command generation now uses the configured token instead of hardcoded "dummy"

Usage

# Start server with auth
copilot-api start --anthropic-auth-token my-secret-token

# Clients authenticate via either header:
curl -H "x-api-key: my-secret-token" http://localhost:4141/v1/messages
curl -H "Authorization: Bearer my-secret-token" http://localhost:4141/v1/messages

Unauthenticated or incorrect tokens receive a 401 response:

{ "error": { "message": "Invalid or missing authentication token", "type": "authentication_error" } }

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 4 commits February 6, 2026 08:20
Co-authored-by: backwind1233 <4465723+backwind1233@users.noreply.github.com>
Co-authored-by: backwind1233 <4465723+backwind1233@users.noreply.github.com>
Co-authored-by: backwind1233 <4465723+backwind1233@users.noreply.github.com>
…ddleware

Co-authored-by: backwind1233 <4465723+backwind1233@users.noreply.github.com>
Copilot AI changed the title [WIP] Add option for ANTHROPIC_AUTH_TOKEN customization feat: add --anthropic-auth-token option for API access protection Feb 6, 2026
Copilot AI requested a review from backwind1233 February 6, 2026 08:24
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