Skip to content

Commit 2f3857d

Browse files
committed
feat: show API key SHA256 hash instead of asterisk masking
Replace the generic asterisk masking with a deterministic SHA256 hash prefix to allow developers to verify which API key is being used while maintaining security. Changes: - Add hashlib import for SHA256 support - Create openai_api_key_hash helper property - Update config display to show: API_KEY=sha256:<hash_prefix>...
1 parent 9cc2e8c commit 2f3857d

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/core/config.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import os
22
import sys
3+
import hashlib
34

45
# Configuration
56
class Config:
@@ -69,9 +70,20 @@ def get_custom_headers(self):
6970

7071
return custom_headers
7172

73+
@property
74+
def openai_api_key_hash(self):
75+
"""Get the first few characters of SHA256 hash of the OpenAI API key.
76+
77+
This provides a secure way to identify the API key without exposing it.
78+
Returns '<not-set>' if the API key is not configured.
79+
80+
Returns:
81+
str: First few characters of SHA256 hash or '<not-set>'
82+
"""
83+
return "<not-set>" if not self.openai_api_key else 'sha256:' + hashlib.sha256(self.openai_api_key.encode()).hexdigest()[:16] + '...'
84+
7285
try:
7386
config = Config()
74-
print(f" Configuration loaded: API_KEY={'*' * 20}..., BASE_URL='{config.openai_base_url}'")
7587
except Exception as e:
7688
print(f"=4 Configuration Error: {e}")
7789
sys.exit(1)

src/main.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,13 @@ def main():
4242
# Configuration summary
4343
print("🚀 Claude-to-OpenAI API Proxy v1.0.0")
4444
print(f"✅ Configuration loaded successfully")
45+
print(f" OpenAI API Key : {config.openai_api_key_hash}")
4546
print(f" OpenAI Base URL: {config.openai_base_url}")
4647
print(f" Big Model (opus): {config.big_model}")
4748
print(f" Middle Model (sonnet): {config.middle_model}")
4849
print(f" Small Model (haiku): {config.small_model}")
4950
print(f" Max Tokens Limit: {config.max_tokens_limit}")
50-
print(f" Request Timeout: {config.request_timeout}s")
51+
print(f" Request Timeout : {config.request_timeout}s")
5152
print(f" Server: {config.host}:{config.port}")
5253
print(f" Client API Key Validation: {'Enabled' if config.anthropic_api_key else 'Disabled'}")
5354
print("")

0 commit comments

Comments
 (0)