Skip to main content
All requests to the Fortytwo API require authentication using an API key. This guide explains how to use and manage your API keys securely.
Keep your API key secure! Your API key should be treated like a password. Never share it publicly or commit it to version control systems.

Using Your API Key

Include your API key in the Authorization header of every API request using the Bearer authentication scheme:
Authorization: Bearer YOUR_FORTYTWO_API_KEY

Example Request

curl https://api.fortytwo.network/v1/models \
  -H "Authorization: Bearer YOUR_FORTYTWO_API_KEY"

Authentication Errors

If authentication fails, refer to the ‘Errors’ page for details on error codes.

Store API Keys Securely

Store your API key in environment variables rather than hardcoding it:
  • Python
  • JavaScript
Python can not read from .env file by default. You have 2 options:
  • Option 1: Add to machine env
  • Option 2: Read with python-dotenv package
export FORTYTWO_API_KEY=YOUR_FORTYTWO_API_KEY
Python
import os  

api_key = os.getenv('FORTYTWO_API_KEY')

API Key Management

Revoking Keys

Revoking a key immediately invalidates it. Any applications using the revoked key will stop working. You cannot revert this action.

OpenAI Compatibility

The Fortytwo API uses the same authentication format as OpenAI’s API. If you’re migrating from OpenAI, you can simply replace your OpenAI API key with a Fortytwo API key:
# OpenAI
from openai import OpenAI
client = OpenAI(api_key="sk-openai-key")

# Fortytwo
from openai import OpenAI
client = OpenAI(
    api_key="YOUR_FORTYTWO_API_KEY",
    base_url="https://api.fortytwo.network/v1"
)

Troubleshooting

If you experience authentication issues:
  • Verify that your API key is written correctly.
  • Make sure that the Authorization header is properly formatted.
  • Contact support through Discord .