Skip to main content
HaiToken LLM gateway is compatible with OpenAI and Anthropic Claude API protocols. You can get started in three steps: get your API key, call the API, and connect to AI tools.

Step 1: Get your API key

  1. Register and log in to the HaiToken console
  2. Navigate to Token management in the left sidebar
  3. Click Create API Key, enter a name, and generate your key
  4. Copy and securely store the generated API key (it is shown only once)
Keep your API key secure. Do not expose it in client-side code or public repositories.

Step 2: Call the API

HaiToken offers two API formats. Choose the one that matches the model you want to use.

OpenAI format

For OpenAI-compatible models, using the POST /v1/chat/completions protocol.
import requests

url = "https://api.haitoken.ai/v1/chat/completions"
headers = {
    "Authorization": "Bearer YOUR_API_KEY",
    "Content-Type": "application/json"
}
data = {
    "model": "gpt-4o",
    "messages": [
        {"role": "user", "content": "Hello, introduce yourself please"}
    ]
}

response = requests.post(url, json=data, headers=headers)
print(response.json())

Claude format

For Anthropic Claude models, using the POST /v1/messages protocol.
When calling the Claude format API, include the anthropic-version header. The recommended value is 2023-06-01.
import requests

url = "https://api.haitoken.ai/v1/messages"
headers = {
    "Authorization": "Bearer YOUR_API_KEY",
    "Content-Type": "application/json",
    "anthropic-version": "2023-06-01"
}
data = {
    "model": "claude-sonnet-4-0",
    "max_tokens": 1024,
    "messages": [
        {"role": "user", "content": "Hello, introduce yourself please"}
    ]
}

response = requests.post(url, json=data, headers=headers)
print(response.json())

Step 3: Connect to AI tools

Once you have your API key and the API is verified, you can connect HaiToken to popular AI coding tools.

Cursor

  1. Open Cursor, go to Settings > Models
  2. Enter your API key in the OpenAI API Key field
  3. Set OpenAI Base URL to https://api.haitoken.ai/v1
  4. Save and select from the available models in the model list

Claude Code

  1. Set environment variables in your terminal:
export ANTHROPIC_API_KEY="YOUR_API_KEY"
export ANTHROPIC_BASE_URL="https://api.haitoken.ai/"
  1. Launch Claude Code to start using it.

Open Code

  1. Add haitoken directly from the OpenCode TUI:
Launch the OpenCode TUI Type /connect In the provider list, choose “Other” (custom endpoint) Fill in: Base URL: https://api.haitoken.ai/v1 API Key: your haitoken API key After saving, type /models and switch to the newly added model
  1. Configure provider and base URL in the opencode.json file at your project root:
"provider": {
    "haitoken": {
      "models": {
        "deepseek-v4-flash": {
          "name": "deepseek-v4-flash"
        },
        "deepseek-v4-pro": {
          "name": "deepseek-v4-pro"
        },
      },
      "name": "haitoken",
      "npm": "@ai-sdk/openai-compatible",
      "options": {
        "baseURL": "https://api.haitoken.ai/v1"
      }
    }
  }
For more AI tool integration guides, see the AI tool integration section.

Next steps