Skip to content

feat: add optional API key authentication#5

Merged
mrjunos merged 1 commit into
mainfrom
feat/api-key-auth
Apr 7, 2026
Merged

feat: add optional API key authentication#5
mrjunos merged 1 commit into
mainfrom
feat/api-key-auth

Conversation

@mrjunos

@mrjunos mrjunos commented Apr 7, 2026

Copy link
Copy Markdown
Owner

Summary

All endpoints are now protected by an X-API-Key header when COMPASS_API_KEY is set in the environment. If the variable is unset (default), auth is disabled — local development requires no configuration changes.

# With auth enabled
curl -H "X-API-Key: my-secret" http://localhost:8000/health

# Without auth (local dev, COMPASS_API_KEY not set)
curl http://localhost:8000/health

Returns 401 on missing or invalid key.

Tests added (53 total, up from 46)

7 new auth tests in TestAuth:

  • Auth disabled when COMPASS_API_KEY unset
  • Valid key accepted (200)
  • Invalid key rejected (401)
  • Missing key rejected (401)
  • Auth enforced on /chat, /upload, /documents

Test plan

  • 53 tests passing
  • CI green

🤖 Generated with Claude Code

All endpoints are now protected by an X-API-Key header when
COMPASS_API_KEY is set. If the env var is unset, auth is disabled
so local development requires no configuration.

Returns 401 on missing or invalid key.

Also adds 7 auth tests covering: no-key mode, valid key, invalid key,
missing key, and auth applied to /chat, /upload, /documents.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@mrjunos
mrjunos merged commit a82e277 into main Apr 7, 2026
1 check passed
@mrjunos
mrjunos deleted the feat/api-key-auth branch April 7, 2026 15:20
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