Skip to content
Sign in

Authentication

API key authentication

SeaWhale AI uses API keys to authenticate you and track usage. Every API request must be authenticated with a token.

Why API keys?

  • Account identification — identifies your account and deducts from your balance
  • Usage tracking — records your API call history and cost breakdown
  • Security management — create, delete or restrict key permissions at any time

Getting an API key

  1. Sign in to the SeaWhale AI console
  2. Open the API key management page
  3. Click "New key"
  4. Give the key a recognizable name
  5. (Optional) Set a credit limit for the key
  6. Copy the key and store it somewhere safe

WARNING

Security note: an API key grants full access to your account. Never expose it in public code or in front-end code.

Usage

Authentication format

The SeaWhale AI API uses standard token authentication and is fully compatible with the OpenAI SDK.

Add this to your HTTP request headers:

Authorization: YOUR_API_KEY
js
import OpenAI from 'openai'

// Initialize the OpenAI SDK pointed at SeaWhale AI
const openai = new OpenAI({
  baseURL: 'https://api.atalk-ai.com/v2', // SeaWhale AI API endpoint
  apiKey: '<API_KEY>', // Replace with your API key
})

async function main() {
  const completion = await openai.chat.completions.create({
    model: 'gpt-4o',
    messages: [{role: 'user', content: 'Hello, this is a test'}],
  })

  console.log(completion.choices[0].message)
}

main()
python
from openai import OpenAI

# Initialize the OpenAI SDK pointed at SeaWhale AI
client = OpenAI(
  base_url="https://api.atalk-ai.com/v2",  # SeaWhale AI API endpoint
  api_key="<API_KEY>",  # Replace with your API key
)

# Send the request
response = client.chat.completions.create(
  model="gpt-4o",
  messages=[
    {"role": "user", "content": "Hello, this is a test"}
  ]
)

# Print the result
print(response.choices[0].message.content)
bash
curl https://api.atalk-ai.com/v2/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: <API_KEY>" \
  -d '{
    "model": "gpt-4o",
    "messages": [
      {"role": "system", "content": "You are a helpful assistant."},
      {"role": "user", "content": "Hello!"}
    ]
  }'

Optional headers

Besides the required Authorization header, you can add the following optional headers:

HTTP-Referer

The URL of your site or application. This helps us:

  • Break down usage by source
  • Provide better technical support

Best practices

1. Key security

  • ❌ Don't: commit API keys to a Git repository
  • ❌ Don't: hard-code API keys in front-end JavaScript
  • ✅ Do: store API keys in environment variables
  • ✅ Do: call the API from your backend

2. Environment variable example

bash
# .env file
SEAWHALE_API_KEY=your_api_key_here
javascript
// Read from the environment
const openai = new OpenAI({
  baseURL: 'https://api.atalk-ai.com/v2',
  apiKey: process.env.SEAWHALE_API_KEY,
})

3. Managing multiple keys

  • Create a separate API key per project or environment
  • Set a sensible credit limit on each key
  • Rotate keys periodically for better security
  • Delete keys you no longer use

FAQ

Q: What if my API key leaks?

Delete the key in the console immediately and create a new one.

Q: How many API keys can I create?

There is no limit — create as many as you need.

Q: Do API keys expire?

Not by default, but you can delete or regenerate one at any time.

Q: What if I forgot to save my API key?

For security reasons a key is shown only once when created. If you did not save it, delete the old key and create a new one.