Authentication

View as Markdown

NeuraAI uses API keys to authenticate requests. All API requests must include a valid API key in the authorization header.

Getting Your API Key

  1. Sign up for a NeuraAI account at neura-ai.app
  2. Navigate to your dashboard
  3. Go to the API Keys section
  4. Click “Create New API Key”
  5. Copy and securely store your API key

Keep your API key secure! Never share it publicly or commit it to version control. Treat it like a password.

Authentication Method

NeuraAI uses Bearer token authentication. Include your API key in the Authorization header of every request:

Authorization: Bearer YOUR_API_KEY

Using Authentication

Python (OpenAI SDK)

The recommended way to authenticate is using environment variables:

1import os
2from openai import OpenAI
3
4# Set your API key as an environment variable
5# export NEURA_API_KEY='your-api-key-here'
6
7client = OpenAI(
8 base_url="https://api.neura-ai.app/v1",
9 api_key=os.environ.get("NEURA_API_KEY")
10)
11
12response = client.chat.completions.create(
13 model="gpt-5",
14 messages=[{"role": "user", "content": "Hello!"}]
15)

Alternatively, you can pass the API key directly:

1from openai import OpenAI
2
3client = OpenAI(
4 base_url="https://api.neura-ai.app/v1",
5 api_key="your-api-key-here" # Not recommended for production
6)

cURL

$curl https://api.neura-ai.app/v1/chat/completions \
> -H "Content-Type: application/json" \
> -H "Authorization: Bearer YOUR_API_KEY" \
> -d '{
> "model": "gpt-5",
> "messages": [{"role": "user", "content": "Hello!"}]
> }'

JavaScript/Node.js

1import OpenAI from 'openai';
2
3const client = new OpenAI({
4 baseURL: 'https://api.neura-ai.app/v1',
5 apiKey: process.env.NEURA_API_KEY
6});
7
8const response = await client.chat.completions.create({
9 model: 'gpt-5',
10 messages: [{ role: 'user', content: 'Hello!' }]
11});

Python (Requests)

If you prefer using the requests library directly:

1import requests
2import os
3
4headers = {
5 "Authorization": f"Bearer {os.environ.get('NEURA_API_KEY')}",
6 "Content-Type": "application/json"
7}
8
9data = {
10 "model": "gpt-5",
11 "messages": [{"role": "user", "content": "Hello!"}]
12}
13
14response = requests.post(
15 "https://api.neura-ai.app/v1/chat/completions",
16 headers=headers,
17 json=data
18)
19
20print(response.json())

Setting Environment Variables

Linux/macOS

Add to your .bashrc, .zshrc, or .bash_profile:

$export NEURA_API_KEY='your-api-key-here'

Or set temporarily in your current session:

$export NEURA_API_KEY='your-api-key-here'

Windows (PowerShell)

1$env:NEURA_API_KEY='your-api-key-here'

Windows (Command Prompt)

1set NEURA_API_KEY=your-api-key-here

Using .env Files

For local development, use a .env file:

$# .env file
$NEURA_API_KEY=your-api-key-here

Then load it in your application:

1from dotenv import load_dotenv
2import os
3from openai import OpenAI
4
5# Load environment variables from .env file
6load_dotenv()
7
8client = OpenAI(
9 base_url="https://api.neura-ai.app/v1",
10 api_key=os.environ.get("NEURA_API_KEY")
11)

Install python-dotenv:

$pip install python-dotenv

Managing API Keys

Creating Multiple Keys

You can create multiple API keys for different applications or environments:

  • Development - For testing and development
  • Staging - For pre-production testing
  • Production - For live applications

This allows you to:

  • Rotate keys without downtime
  • Track usage per application
  • Revoke compromised keys without affecting others

Rotating Keys

Best practice is to rotate API keys periodically:

  1. Create a new API key
  2. Update your application to use the new key
  3. Test that the new key works
  4. Delete the old key

Revoking Keys

If you suspect a key has been compromised:

  1. Go to your dashboard
  2. Navigate to API Keys
  3. Click “Revoke” on the compromised key
  4. Create a new key immediately
  5. Update your applications

Error Responses

Invalid API Key

1{
2 "error": {
3 "message": "Invalid API key provided",
4 "type": "invalid_request_error",
5 "code": "invalid_api_key"
6 }
7}

HTTP Status: 401 Unauthorized

Missing API Key

1{
2 "error": {
3 "message": "You didn't provide an API key",
4 "type": "invalid_request_error",
5 "code": "missing_api_key"
6 }
7}

HTTP Status: 401 Unauthorized

Expired API Key

1{
2 "error": {
3 "message": "This API key has been revoked",
4 "type": "invalid_request_error",
5 "code": "revoked_api_key"
6 }
7}

HTTP Status: 401 Unauthorized

Security Best Practices

DO:

  • ✅ Store API keys in environment variables
  • ✅ Use different keys for different environments
  • ✅ Rotate keys regularly (every 90 days recommended)
  • ✅ Revoke unused or old keys
  • ✅ Monitor API usage for unusual activity
  • ✅ Use .gitignore to exclude .env files from version control
  • ✅ Limit key permissions when possible

DON’T:

  • ❌ Hardcode API keys in your source code
  • ❌ Commit API keys to version control (Git, SVN, etc.)
  • ❌ Share API keys via email or messaging apps
  • ❌ Use the same key across multiple applications
  • ❌ Expose keys in client-side code (JavaScript, mobile apps)
  • ❌ Log API keys in application logs
  • ❌ Store keys in publicly accessible locations

Rate Limiting

API keys are subject to rate limits based on your subscription tier. See the Pricing page for details.

If you exceed your rate limit, you’ll receive:

1{
2 "error": {
3 "message": "Rate limit exceeded",
4 "type": "rate_limit_error",
5 "code": "rate_limit_exceeded"
6 }
7}

HTTP Status: 429 Too Many Requests

Testing Your Authentication

Quick test to verify your API key works:

1from openai import OpenAI
2
3client = OpenAI(
4 base_url="https://api.neura-ai.app/v1",
5 api_key="your-api-key-here"
6)
7
8try:
9 models = client.models.list()
10 print("✅ Authentication successful!")
11 print(f"Available models: {len(models.data)}")
12except Exception as e:
13 print(f"❌ Authentication failed: {e}")

Need Help?

If you’re having authentication issues:

  1. Verify your API key is correct (copy-paste to avoid typos)
  2. Check that the key hasn’t been revoked
  3. Ensure you’re using the correct base URL: https://api.neura-ai.app/v1
  4. Verify the Authorization header format: Bearer YOUR_KEY
  5. Contact support if issues persist