Learn how to authenticate with the HelpingAI API and manage your API keys securely.
Important: Keep your API key secure and never expose it in client-side code or public repositories.
Set your API key as an environment variable:
# Linux/macOS {#linuxmacos}
export HELPINGAI_API_KEY="your-api-key-here"
# Windows {#windows}
set HELPINGAI_API_KEY=your-api-key-hereimport os
import requests
api_key = os.getenv("HELPINGAI_API_KEY")
headers = {
"Authorization": f"Bearer {api_key}",
"Content-Type": "application/json"
}
response = requests.post(
"https://api.helpingai.co/v1/chat/completions",
headers=headers,
json={
"model": "Dhanishtha-2.0-preview",
"messages": [{"role": "user", "content": "Hello!"}]
}
)import os
from openai import OpenAI
client = OpenAI(
base_url="https://api.helpingai.co/v1",
api_key=os.getenv("HELPINGAI_API_KEY")
)
response = client.chat.completions.create(
model="Dhanishtha-2.0-preview",
messages=[{"role": "user", "content": "Hello!"}]
)import os
from helpingai import HelpingAI
client = HelpingAI(api_key=os.getenv("HELPINGAI_API_KEY"))
response = client.chat.completions.create(
model="Dhanishtha-2.0-preview",
messages=[{"role": "user", "content": "Hello!"}]
)const axios = require('axios');
const apiKey = process.env.HELPINGAI_API_KEY;
const response = await axios.post(
'https://api.helpingai.co/v1/chat/completions',
{
model: 'Dhanishtha-2.0-preview',
messages: [{role: 'user', content: 'Hello!'}]
},
{
headers: {
'Authorization': `Bearer ${apiKey}`,
'Content-Type': 'application/json'
}
}
);import OpenAI from 'openai';
const openai = new OpenAI({
baseURL: 'https://api.helpingai.co/v1',
apiKey: process.env.HELPINGAI_API_KEY
});
const response = await openai.chat.completions.create({
model: 'Dhanishtha-2.0-preview',
messages: [{role: 'user', content: 'Hello!'}]
});import { HelpingAI } from 'helpingai';
const client = new HelpingAI({
apiKey: process.env.HELPINGAI_API_KEY
});
const response = await client.chat.completions.create({
model: 'Dhanishtha-2.0-preview',
messages: [{role: 'user', content: 'Hello!'}]
});If you can't use environment variables, you can pass the API key directly:
import requests
headers = {
"Authorization": "Bearer your-api-key-here",
"Content-Type": "application/json"
}
response = requests.post(
"https://api.helpingai.co/v1/chat/completions",
headers=headers,
json={
"model": "Dhanishtha-2.0-preview",
"messages": [{"role": "user", "content": "Hello!"}]
}
)from openai import OpenAI
client = OpenAI(
base_url="https://api.helpingai.co/v1",
api_key="your-api-key-here"
)from helpingai import HelpingAI
client = HelpingAI(api_key="your-api-key-here")const response = await axios.post(
'https://api.helpingai.co/v1/chat/completions',
{
model: 'Dhanishtha-2.0-preview',
messages: [{role: 'user', content: 'Hello!'}]
},
{
headers: {
'Authorization': 'Bearer your-api-key-here',
'Content-Type': 'application/json'
}
}
);const openai = new OpenAI({
baseURL: 'https://api.helpingai.co/v1',
apiKey: 'your-api-key-here'
});const client = new HelpingAI({
apiKey: 'your-api-key-here'
});To rotate your API key:
You can create multiple API keys for different purposes:
❌ Don't do this:
// Never put API keys in client-side code
const apiKey = "sk-helpingai-abc123..."; // Visible to users!
// Never commit API keys to version control
const config = {
apiKey: "sk-helpingai-abc123..." // Will be in git history!
};✅ Do this instead:
// Use environment variables
const apiKey = process.env.HELPINGAI_API_KEY;
// Or use a secure configuration service
const apiKey = await getSecretFromVault('helpingai-api-key');API keys should only be used in server-side applications:
For client-side applications, create a proxy endpoint:
// Your backend server
app.post('/api/chat', async (req, res) => {
const response = await fetch('https://api.helpingai.co/v1/chat/completions', {
method: 'POST',
headers: {
'Authorization': `Bearer ${process.env.HELPINGAI_API_KEY}`,
'Content-Type': 'application/json'
},
body: JSON.stringify(req.body)
});
const data = await response.json();
res.json(data);
});
// Your frontend
const response = await fetch('/api/chat', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
model: 'Dhanishtha-2.0-preview',
messages: [{role: 'user', content: 'Hello!'}]
})
});Handle authentication errors gracefully:
try:
response = client.chat.completions.create(
model="Dhanishtha-2.0-preview",
messages=[{"role": "user", "content": "Hello!"}]
)
except Exception as e:
if "authentication" in str(e).lower():
print("Invalid API key. Please check your credentials.")
elif "unauthorized" in str(e).lower():
print("API key may be expired or revoked.")
else:
print(f"Error: {e}")try {
const response = await client.chat.completions.create({
model: 'Dhanishtha-2.0-preview',
messages: [{role: 'user', content: 'Hello!'}]
});
} catch (error) {
if (error.status === 401) {
console.error('Invalid API key. Please check your credentials.');
} else if (error.status === 403) {
console.error('API key may be expired or insufficient permissions.');
} else {
console.error('Error:', error.message);
}
}Test your authentication setup:
def test_authentication():
try:
response = client.chat.completions.create(
model="Dhanishtha-2.0-preview",
messages=[{"role": "user", "content": "Test"}],
max_tokens=5
)
print("✅ Authentication successful!")
return True
except Exception as e:
print(f"❌ Authentication failed: {e}")
return False
test_authentication()async function testAuthentication() {
try {
const response = await client.chat.completions.create({
model: 'Dhanishtha-2.0-preview',
messages: [{role: 'user', content: 'Test'}],
max_tokens: 5
});
console.log('✅ Authentication successful!');
return true;
} catch (error) {
console.error('❌ Authentication failed:', error.message);
return false;
}
}
testAuthentication();Once you have authentication working:
Having trouble with authentication?