Overview
Sawmills supports two types of API keys:- User API Keys: Personal API keys that can be created by individual users for their own use
- Organization API Keys: System-level API keys for organization-wide access (currently only used by Sawmills itself)
Obtaining Your JWT Token
Before creating API keys, you need to obtain a JWT token from the Sawmills UI. This token is used to authenticate your requests to the API.Method 1: Using Chrome DevTools
- Log in to Sawmills: Open https://app.sawmills.ai in Chrome
- Open DevTools: Press
F12or right-click and select “Inspect” - Go to Network Tab: Click on the “Network” tab in DevTools
- Filter Requests: In the filter box, type “api” to see API requests
- Find a Request: Look for any request to
api.sawmills.ai(you may need to navigate around the UI to trigger API calls) - Check Headers: Click on the request and look at the “Request Headers” section
- Copy the Token: Find the
Authorizationheader and copy the JWT token (the part after “Bearer “)
Method 2: Using Application Storage
- Log in to Sawmills: Open https://app.sawmills.ai in Chrome
- Open DevTools: Press
F12or right-click and select “Inspect” - Go to Application Tab: Click on the “Application” tab
- Check Local Storage: In the left sidebar, expand “Local Storage” and click on the Sawmills domain
- Find Token: Look for keys containing “token”, “jwt”, or “auth” and copy the JWT value
Token Expiration: JWT tokens expire after a certain period. If you get authentication errors, you may need to refresh the page and obtain a new token.
Creating a User API Key
Prerequisites
- You must be authenticated with a valid Sawmills account
- You must have appropriate permissions to create API keys in your organization
- You need a JWT token from the Sawmills UI (see Obtaining Your JWT Token below)
API Endpoint
Request Body
label(optional): A human-readable name for your API key (max 255 characters)
Response
Example: Creating an API Key with cURL
JWT Token: Replace
YOUR_JWT_TOKEN with the JWT token you obtain from the Sawmills UI. See Obtaining Your JWT Token for instructions.Example: Creating an API Key with JavaScript
Managing API Keys
Listing Your API Keys
page(optional): Page number for pagination (default: 1)limit(optional): Number of keys per page (default: 20, max: 100)include_revoked(optional): Include revoked keys in results (default: false)
Getting a Specific API Key
Revoking an API Key
Revoking an API key immediately invalidates it and prevents any further use. This action cannot be undone.
Security Best Practices
Storage
- Store API keys in environment variables or secure key management systems
- Never commit API keys to version control
- Use different API keys for different environments (development, staging, production)
Rotation
- Regularly rotate your API keys
- Use short-lived keys when possible
- Revoke unused or compromised keys immediately
Error Handling
Common Error Responses
401 UnauthorizedTroubleshooting
API Key Not Working
- Check the format: Ensure your API key follows the correct format
- Verify environment: Make sure you’re using the correct environment prefix
- Check status: Ensure the API key is active and not revoked
- Verify scopes: Confirm the API key has the required permissions
Common Issues
“Invalid API key format”- Check that the API key is correctly formatted
- Verify the key is complete and not truncated
- The API key has been revoked and cannot be used
- Create a new API key to continue
- The API key is malformed or corrupted
- Verify the key was copied correctly without extra characters