Subscription Keys in Azure API Management
Overview
Subscription keys are the primary mechanism for controlling and monitoring access to your APIs in Azure API Management. Think of a subscription key as a membership card - it identifies who is accessing your APIs and allows you to track usage, apply rate limits, and revoke access when needed. Every API consumer must subscribe to a product or API to receive a valid key.
What You'll Learn
- How subscription keys work to secure your APIs
- Creating and managing subscriptions
- Using keys in API requests (header vs query parameter)
- Best practices for key rotation and security
Why Subscription Keys Matter
Subscription keys provide several important capabilities:
- Access Control - Only subscribers with valid keys can access your APIs
- Usage Tracking - Monitor which applications are calling which APIs
- Rate Limiting - Apply different limits to different subscription tiers
- Revocation - Quickly disable access for compromised keys without affecting other users
How It Works
- Subscriber subscribes to a product
- APIM generates two keys (primary and secondary)
- Caller includes key in request
- APIM validates key before forwarding
Create Subscription
Via Portal
- Go to APIM → Subscriptions
- Click + Add subscription
- Configure:
- Name: "Developer Subscription"
- Scope: Product (or API)
- Product: Select product
- Click Save
Keys Generated
- Primary key:
abcdef123456... - Secondary key:
123456abcdef...
Using the Key
Header (Recommended)
Ocp-Apim-Subscription-Key: <your-key>
Query Parameter
https://my-apim.azure-api.net/products?subscription-key=<your-key>
Enable/Disable Subscriptions
Per Product
- Go to APIM → Products
- Select product
- Toggle Require subscription
Per API
- Select API → Settings
- Toggle Subscription required
Product Subscriptions
Why Use Products?
- Group APIs together
- Apply common policies
- Simplify subscription
Common Setup
Product: "Gold Tier"
├─ API A
├─ API B
└─ API C
Users subscribe to "Gold Tier"
→ Access all APIs in product
Best Practices
- Rotate keys - Regenerate keys periodically
- Use different keys - Per environment or user
- Revoke compromised keys - Use secondary if primary leaked
- Scope appropriately - Product vs API level
Next Steps
- Explore Developer Portal
Azure Integration Hub - Beginner Level