API Reference
Complete reference for B2ALABS AI Gateway API - 102 endpoints across 19 categories
Press ⌘K or Ctrl+K to search
Base URL
https://api.b2alabs.comAuthentication
All API requests require authentication using an API key in the Authorization header:
Authorization: Bearer YOUR_API_KEYError Responses
The API uses standard HTTP status codes to indicate success or failure. All error responses follow a consistent JSON structure.
Error Response Format
All errors return this consistent JSON structure
{
"success": false,
"error": {
"code": "error_code",
"message": "Human-readable error message",
"details": {
// Additional error-specific information
}
}
}Bad Request
Invalid request parameters or malformed JSON
{
"success": false,
"error": {
"code": "invalid_request",
"message": "Invalid request body",
"details": {
"field": "email",
"issue": "Invalid email format"
}
}
}Unauthorized
Missing or invalid API key
{
"success": false,
"error": {
"code": "unauthorized",
"message": "Invalid or missing API key",
"details": {
"hint": "Include Authorization header with Bearer token"
}
}
}Forbidden
Insufficient permissions for this resource
{
"success": false,
"error": {
"code": "forbidden",
"message": "Insufficient permissions",
"details": {
"required": "admin",
"current": "user"
}
}
}Not Found
Resource does not exist
{
"success": false,
"error": {
"code": "not_found",
"message": "Resource not found",
"details": {
"resource": "api_key",
"id": "key_123456789"
}
}
}Too Many Requests
Rate limit exceeded
{
"success": false,
"error": {
"code": "rate_limit_exceeded",
"message": "Rate limit exceeded",
"details": {
"limit": 1000,
"remaining": 0,
"reset": 1697443200
}
}
}Internal ServerIcon Error
Unexpected server error occurred
{
"success": false,
"error": {
"code": "internal_error",
"message": "An unexpected error occurred",
"details": {
"request_id": "req_abc123xyz",
"timestamp": "2025-10-16T00:00:00Z"
}
}
}Error Handling Best Practices
JavaScript Example
try {
const response = await fetch('https://api.b2alabs.com/api/v1/auth/api-keys', {
headers: {
'Authorization': 'Bearer YOUR_API_KEY'
}
});
if (!response.ok) {
const error = await response.json();
if (response.status === 401) {
console.error('Authentication failed:', error.error.message);
// Redirect to login or refresh token
} else if (response.status === 429) {
console.error('Rate limit exceeded. Retry after:', error.error.details.reset);
// Implement retry logic with exponential backoff
} else {
console.error('API error:', error.error.message);
}
throw new Error(error.error.message);
}
const data = await response.json();
return data;
} catch (err) {
console.error('Request failed:', err);
throw err;
}Python Example
import requests
import time
def make_api_request(url, headers):
try:
response = requests.get(url, headers=headers)
response.raise_for_status()
return response.json()
except requests.exceptions.HTTPError as e:
error_data = response.json()
if response.status_code == 401:
print(f"Authentication failed: {error_data['error']['message']}")
# Handle authentication failure
elif response.status_code == 429:
reset_time = error_data['error']['details']['reset']
wait_time = reset_time - time.time()
print(f"Rate limited. Waiting {wait_time} seconds...")
time.sleep(wait_time)
return make_api_request(url, headers) # Retry
else:
print(f"API error: {error_data['error']['message']}")
raise
except requests.exceptions.RequestException as e:
print(f"Request failed: {e}")
raiseKeyIcon Recommendations
- Always check the HTTP status code before parsing the response
- Implement exponential backoff for rate limit (429) errors
- Log error details including request_id for debugging
- Handle authentication errors (401) by refreshing tokens or redirecting to login
- Display user-friendly error messages based on error codes
- Monitor 5xx errors and report to your error tracking service
Authentication Endpoints
/api/v1/auth/registerRegister a new user account
Request Body
{
"email": "user@example.com",
"password": "SecurePassword123!",
"name": "John Doe"
}Response (201 Created)
{
"success": true,
"data": {
"user": {
"id": "usr_123456789",
"email": "user@example.com",
"name": "John Doe",
"created_at": "2025-10-16T00:00:00Z"
},
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"refresh_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
}
}CodeBracketIcon Examples
curl -X POST https://api.b2alabs.com/api/v1/auth/register \
-H "Content-Type: application/json" \
-d '{
"email": "user@example.com",
"password": "SecurePassword123!",
"name": "John Doe"
}'const response = await fetch('https://api.b2alabs.com/api/v1/auth/register', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
email: 'user@example.com',
password: 'SecurePassword123!',
name: 'John Doe'
})
});
const data = await response.json();
console.log(data.data.token);import requests
response = requests.post(
'https://api.b2alabs.com/api/v1/auth/register',
json={
'email': 'user@example.com',
'password': 'SecurePassword123!',
'name': 'John Doe'
}
)
data = response.json()
print(data['data']['token'])/api/v1/auth/loginAuthenticate and receive access tokens
Request Body
{
"email": "user@example.com",
"password": "SecurePassword123!"
}Response (200 OK)
{
"success": true,
"data": {
"user": {
"id": "usr_123456789",
"email": "user@example.com",
"name": "John Doe"
},
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"refresh_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"expires_in": 3600
}
}CodeBracketIcon Examples
curl -X POST https://api.b2alabs.com/api/v1/auth/login \
-H "Content-Type: application/json" \
-d '{
"email": "user@example.com",
"password": "SecurePassword123!"
}'const response = await fetch('https://api.b2alabs.com/api/v1/auth/login', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
email: 'user@example.com',
password: 'SecurePassword123!'
})
});
const data = await response.json();
localStorage.setItem('token', data.data.token);import requests
response = requests.post(
'https://api.b2alabs.com/api/v1/auth/login',
json={
'email': 'user@example.com',
'password': 'SecurePassword123!'
}
)
data = response.json()
token = data['data']['token']Try It
Test this endpoint interactively with live requests
/api/v1/auth/meGet current authenticated user information
Response (200 OK)
{
"success": true,
"data": {
"user": {
"id": "usr_123456789",
"email": "user@example.com",
"name": "John Doe",
"role": "user",
"created_at": "2025-10-16T00:00:00Z"
}
}
}CodeBracketIcon Examples
const response = await fetch('https://api.b2alabs.com/api/v1/auth/me', {
headers: {
'Authorization': 'Bearer ' + token
}
});
const data = await response.json();
console.log(data.data.user);import requests
response = requests.get(
'https://api.b2alabs.com/api/v1/auth/me',
headers={'Authorization': 'Bearer YOUR_TOKEN'}
)
data = response.json()
print(data['data']['user'])Try It
Test this endpoint interactively with live requests