AI API Authentication Guide

Secure your API keys. Protect your credentials. Prevent unauthorized access. A developer's complete security checklist.

The Bearer Token Pattern

All major AI APIs use the same authentication pattern: an Authorization header with a Bearer token.

Authorization: Bearer YOUR_API_KEY

This is the OpenAI-compatible standard that TokenEase, DeepSeek, K3, GLM, Qwen, and Doubao all support. One pattern works everywhere.

Environment Variables: The Only Safe Place

Never hardcode API keys in your source code. Use environment variables.

# .env file (never commit this to Git)
OPENAI_API_KEY=sk-xxxxxxxxxxxxxxxxxxxxxxxx
TOKEN_EASE_KEY=tk_your_token_here

# Python
import os
api_key = os.getenv("TOKEN_EASE_KEY")

# Node.js
const apiKey = process.env.TOKEN_EASE_KEY;
Critical: Add .env to your .gitignore immediately. One accidental commit and your key is public forever — even if you delete it later, it stays in Git history.

Security Checklist

What NOT To Do

Client-Side Protection

If you're building a web app that calls AI APIs from the browser, never put your API key in client-side JavaScript. Anyone can open DevTools and steal it.

Solution: Use a backend proxy. Your frontend calls your server, your server calls the AI API with the key. This also lets you add rate limiting, logging, and user authentication.
// ❌ DON'T: Exposing key in browser
const response = await fetch("https://tokenease.io/v1/chat/completions", {
    headers: { "Authorization": "Bearer sk-EXPOSED_KEY" }  // Anyone can see this!
});

// ✅ DO: Proxy through your backend
const response = await fetch("/api/chat", {  // Your server endpoint
    method: "POST",
    body: JSON.stringify({ message: "Hello" })
});

Revoking a Compromised Key

If you suspect your key has been leaked, act immediately:

  1. Generate a new API key in your dashboard
  2. Update the environment variable on your server
  3. Restart your application
  4. Revoke the old key
  5. Check usage logs for unauthorized activity
  6. Audit where the old key was stored (CI/CD, Docker, team members)
With TokenEase, you can revoke a key instantly from the dashboard. All requests with the old key immediately return 401, while your new key works seamlessly across all models.

Detecting Key Theft

Watch for these warning signs:

Authentication at TokenEase

TokenEase uses the standard OpenAI Bearer token format:

curl https://tokenease.io/v1/chat/completions \\
  -H "Authorization: Bearer tk_your_api_key" \\
  -H "Content-Type: application/json" \\
  -d '{"model":"k3","messages":[{"role":"user","content":"Hello"}]}'

Security features built in:

Secure Your AI Integration

Get a free API key with built-in security monitoring, rate limiting, and usage tracking.

Get Free API Key