Skip to main content

Authentication Overview

The Metaculus API uses token-based authentication for all API requests. You must include a valid API token in the Authorization header of every request.
All API requests require valid authentication credentials. Unauthenticated requests will be rejected with a 401 Unauthorized error.

Getting Your API Token

To obtain your API token:
  1. Log in to your Metaculus account
  2. Navigate to your Account Settings
  3. Scroll to the “API Access” section
  4. Click to generate a new token or view your existing token
Keep your API token secret! Anyone with your token can make API requests on your behalf. Never commit tokens to version control or share them publicly.

Token Format

API tokens are 40-character hexadecimal strings, for example:

Making Authenticated Requests

Include your token in the Authorization header with the Token prefix:
The format is: Token (literal string) + single space + your API token.

Example Requests

Authentication Errors

Common authentication error responses:

401 Unauthorized - Missing Token

Solution: Ensure you’ve included the Authorization header in your request.

401 Unauthorized - Invalid Token

Solution: Verify your token is correct. Generate a new token from your account settings if needed.

403 Forbidden

Solution: You’re authenticated but don’t have permission to access this resource. Check if the resource requires special permissions or if you’re accessing a private tournament.

Token Security Best Practices

Follow these security practices to protect your API token:

Use Environment Variables

Never hardcode tokens in your source code. Use environment variables instead:

Rotate Tokens Regularly

For production applications, consider rotating your API tokens periodically:
  1. Generate a new token from your account settings
  2. Update your application to use the new token
  3. Revoke the old token once migration is complete
You can also rotate your API token programmatically using the API:
After rotating your token, your old token will be immediately invalidated. Make sure to update your application with the new token before the rotation completes.

Limit Token Exposure

  • Don’t log tokens in application logs
  • Don’t commit tokens to version control (.env files should be in .gitignore)
  • Don’t share tokens in public channels or forums
  • Use separate tokens for different applications or environments

Token Usage for Bots

API tokens are the recommended authentication method for automated bots and integrations. Session-based authentication is primarily for web users.
If you’re building a forecasting bot or automated system:
  1. Generate a dedicated API token for your bot
  2. Consider creating a separate Metaculus account for your bot
  3. Clearly indicate in your bot’s profile that it’s automated
  4. Respect rate limits to avoid disrupting the service

Testing Authentication

Test your authentication setup with this simple request:
Successful authentication returns a 200 status code:
Failed authentication returns a 401 status code: