Scope 2: Project = "Backend API"
- Allow topics: api/public/**
- Deny tags: production
Result: Access to development/staging frontend resources AND public API topics (except production)</code></pre>
<h3>Example: Cross-Project Documentation Access</h3> <pre><code>Scope 1: Topic Pattern = "**/documentation/**" - Allow tags: publicScope 2: Topic Pattern = "**/readme"
Result: Access to all documentation topics tagged "public" AND all readme topics across all projects</code></pre>
<h3>Best Practices for Multiple Scopes</h3> <ul> <li><strong>Start minimal:</strong> Begin with the most restrictive scope and add more only when needed</li> <li><strong>Use descriptive names:</strong> Name your API keys clearly to indicate what scopes they have</li> <li><strong>Document your strategy:</strong> Keep notes on why each scope was added</li> <li><strong>Review regularly:</strong> Audit API key scopes quarterly and remove unnecessary permissions</li> </ul> <h2>Step-by-Step: Creating a Scoped API Key</h2> <h3>Step 1: Navigate to API Keys</h3> <p>From your dashboard, go to <strong>Account → API Keys</strong>.</p> <h3>Step 2: Click "Generate New Key"</h3> <p>Enter a descriptive name and optional description for your key.</p> <h3>Step 3: Set Expiration</h3> <p>Choose an expiration period (maximum 90 days). Shorter periods are more secure.</p> <h3>Step 4: Add Scopes</h3> <p>Click <strong>"+ Add Scope"</strong> and select a scope type:</p> <p><strong>For Organization-Wide:</strong></p> <ol> <li>Select "Org-wide" tab</li> <li>Optionally add allow/deny filters for topics and tags</li> <li>Add a description explaining what this scope is for</li> </ol> <p><strong>For Project-Specific:</strong></p> <ol> <li>Select "Project" tab</li> <li>Choose a project from the searchable dropdown</li> <li>Optionally restrict to specific topics (topics from the selected project will appear as suggestions)</li> <li>Add allow/deny tags as needed</li> </ol> <p><strong>For Topic Pattern:</strong></p> <ol> <li>Select "Topic Pattern" tab</li> <li>Enter a pattern using <code>*</code> and <code>**</code> wildcards</li> <li>Add allow/deny filters for fine-grained control</li> </ol> <h3>Step 5: Add Multiple Scopes (Optional)</h3> <p>Click <strong>"+ Add Scope"</strong> again to add additional scope rules. Remember, the key will have access to the union of all scopes.</p> <h3>Step 6: Review and Generate</h3> <p>Review your scope configuration. Once satisfied, click <strong>"Generate Key"</strong>.</p> <p><strong>Important:</strong> Copy your API key immediately. It will only be shown once for security reasons.</p> <h2>Common Patterns and Examples</h2> <h3>Read-Only Documentation Access</h3> <pre><code>Type: Topic Pattern Pattern: **/docs/** Allow Tags: public, published Deny Tags: draft, internal</code></pre> <h3>Multi-Project Development Access</h3> <pre><code>Scope 1: Type: Project Project: Frontend App Allow Tags: development, stagingScope 2: Type: Project Project: Backend API Allow Tags: development, staging</code></pre>
<h3>Environment-Specific Access</h3> <pre><code>Type: Organization-wide Allow Tags: production Deny Topics: **/secrets/**, **/credentials/**</code></pre> <h3>Contractor Limited Access</h3> <pre><code>Type: Topic Pattern Pattern: projects/website/frontend/** Allow Tags: contractor-visible Deny Topics: **/pricing/**, **/analytics/** Expiration: 30 days</code></pre> <h2>Security Best Practices</h2> <ol> <li><strong>Principle of Least Privilege:</strong> Grant only the minimum access required</li> <li><strong>Use Project Scopes by Default:</strong> Organization-wide access should be rare</li> <li><strong>Set Short Expirations:</strong> Use 7-30 days for development, 90 days maximum for production</li> <li><strong>Rotate Keys Regularly:</strong> Use the rotation feature to update keys without downtime</li> <li><strong>Monitor Usage:</strong> Check the "Last Used" timestamp to identify unused keys</li> <li><strong>Revoke Immediately:</strong> Remove access for departed team members or compromised keys</li> <li><strong>Tag Strategically:</strong> Use tags to enable scope-based access control</li> <li><strong>Document Key Purpose:</strong> Use descriptions to track why each key exists</li> </ol> <h2>Troubleshooting Access Issues</h2> <h3>"Access Denied" Errors</h3> <p>If your API key is getting access denied errors:</p> <ol> <li>Check that the key hasn't expired</li> <li>Verify the scope includes the project/topic you're accessing</li> <li>Check deny filters - they override allow filters</li> <li>Ensure the topic/memory has the required tags if using tag filters</li> </ol> <h3>Scope Not Working as Expected</h3> <p>Common issues:</p> <ul> <li><strong>Wildcard confusion:</strong> Remember <code>*</code> is one segment, <code>**</code> is many</li> <li><strong>Filter conflicts:</strong> Deny rules take precedence over allow rules</li> <li><strong>Multiple scopes:</strong> The key gets the union of all scopes, which may be broader than expected</li> </ul> <h2>Next Steps</h2> <p>Now that you understand API key scopes, you can:</p> <ul> <li>Create keys with appropriate access levels for your integrations</li> <li>Review and tighten permissions on existing keys</li> <li>Set up automated key rotation for production systems</li> <li>Explore our <a href="/learn/tutorials">API Integration Tutorials</a></li> </ul> <blockquote> <p><strong>Pro Tip:</strong> Start with overly restrictive scopes and loosen them only when you encounter permission errors. It's easier to add permissions than to discover you've granted too much access.</p> </blockquote>