Authentication¶
Glyph Forge uses API keys for authentication. This guide covers how to obtain and use API keys.
Getting an API Key¶
Sign up at glyphapi.ai
Navigate to your account settings
Generate a new API key
Copy the key (it starts with
gf_live_orgf_test_)
API Key Types¶
Live Keys (
gf_live_...): For production useTest Keys (
gf_test_...): For development and testing
Using API Keys¶
Method 1: Direct Parameter¶
Pass the API key directly to the client:
from glyph_forge import ForgeClient
client = ForgeClient(api_key="gf_live_your_key_here")
Method 2: Environment Variable¶
Set the GLYPH_API_KEY environment variable:
export GLYPH_API_KEY="gf_live_your_key_here"
Then initialize the client without explicitly passing the key:
from glyph_forge import ForgeClient
# Automatically reads from GLYPH_API_KEY env var
client = ForgeClient()
Method 3: .env File¶
Use a .env file for managing environment variables:
# .env file
GLYPH_API_KEY=gf_live_your_key_here
GLYPH_API_BASE=https://api.glyphapi.ai
Load it with python-dotenv:
from dotenv import load_dotenv
from glyph_forge import ForgeClient
load_dotenv() # Load .env file
client = ForgeClient() # Uses env var
Custom Base URL¶
For self-hosted or regional deployments, specify a custom base URL:
client = ForgeClient(
api_key="gf_live_...",
base_url="https://api.glyphapi.ai"
)
Or via environment variable:
export GLYPH_API_BASE="https://api.glyphapi.ai"
Security Best Practices¶
Never commit API keys to version control
Add
.envto your.gitignore:# .gitignore .env *.key
Use environment variables in production
Set environment variables through your deployment platform (Heroku, AWS, etc.)
Rotate keys regularly
Generate new keys periodically and revoke old ones
Use test keys for development
Keep live keys separate from test keys
Limit key permissions
Use different keys for different applications or teams
Rate Limiting¶
API keys are subject to rate limits based on your subscription tier. The client automatically includes rate limit information in responses:
from glyph_forge import ForgeClient
client = ForgeClient(api_key="gf_live_...")
# Make a request
schema = client.build_schema_from_docx(ws, docx_path="template.docx")
# Check rate limit status
if client.last_rate_limit_info:
print(f"Tier: {client.last_rate_limit_info['X-Subscription-Tier']}")
print(f"Remaining: {client.last_rate_limit_info['X-Requests-Remaining']}")
Error Handling¶
Handle authentication errors gracefully:
from glyph_forge import ForgeClient
from glyph_forge.core.client.exceptions import ForgeClientHTTPError
try:
client = ForgeClient(api_key="invalid_key")
schema = client.build_schema_from_docx(ws, docx_path="template.docx")
except ForgeClientHTTPError as e:
if e.status_code == 401:
print("Invalid API key")
elif e.status_code == 403:
print("Account inactive or no subscription")
elif e.status_code == 429:
print("Rate limit exceeded")
else:
print(f"HTTP Error: {e}")