Every request you send to the NexLLM API must include your API key for authentication. For standard OpenAI-compatible requests, you pass the key as a Bearer token in the Authorization header. NexLLM also supports native provider authentication formats for Claude and Gemini, which use different header conventions.
Standard Authentication
Include your API key in the Authorization header as a Bearer token on every request:
Authorization: Bearer sk-xxxxxxxxxxxxxxxx
Example: curl
curl https://www.nexllm.ai/v1/chat/completions \
-H "Authorization: Bearer sk-xxxxxxxxxxxxxxxx" \
-H "Content-Type: application/json" \
-d '{"model": "gpt-4o", "messages": [{"role": "user", "content": "Hello"}]}'
Example: OpenAI SDK (Python)
Configure the OpenAI client with your NexLLM API key and base URL — all subsequent calls are authenticated automatically:
from openai import OpenAI
client = OpenAI(
api_key="sk-xxxxxxxxxxxxxxxx",
base_url="https://www.nexllm.ai/v1"
)
Native Provider Authentication
If you prefer to use provider-native request formats, NexLLM supports their authentication conventions as well.
Instead of the Authorization header, pass your key in the x-api-key header. You must also include the anthropic-version header:
curl https://www.nexllm.ai/v1/messages \
-H "x-api-key: sk-xxxxxxxxxxxxxxxx" \
-H "anthropic-version: 2023-06-01" \
-H "content-type: application/json" \
-d '{
"model": "aws/claude-haiku-4-5",
"system": "You are a helpful assistant.",
"max_tokens": 100,
"messages": [
{
"role": "user",
"content": "Write a short welcome message for a new user."
}
]
}'
Pass your API key as a key query parameter on the Gemini-format endpoint:
curl "https://www.nexllm.ai/v1beta/models/gemini-2.5-flash:generateContent?key=sk-xxxxxxxx" \
-H "Content-Type: application/json" \
-d '{"contents": [{"parts": [{"text": "Hello"}]}]}'
Security Best Practices
Keep your API key secret at all times. Never hard-code it in client-side code, commit it to source control, or share it publicly. If a key is compromised, rotate it immediately from the NexLLM dashboard.
Use environment variables to manage your key in application code:
export NEXLLM_API_KEY="sk-xxxxxxxxxxxxxxxx"
import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ["NEXLLM_API_KEY"],
base_url="https://www.nexllm.ai/v1"
)
Don’t have an API key yet? Visit the Getting Your API Keys guide to create one from the NexLLM dashboard.