Getting Started
Installation
This guide will walk you through installing the necessary dependencies to use the AI API in your preferred programming language. Since our API is OpenAI-compatible, you can use the official OpenAI SDKs.
JavaScript/Node.js
Prerequisites
- Node.js 18+
- npm, yarn, or pnpm package manager
Install OpenAI SDK
# Using npm
npm install openai
# Using yarn
yarn add openai
# Using pnpm
pnpm add openai
Basic Setup
import OpenAI from "openai";
const openai = new OpenAI({
baseURL: "https://api.akbxr.com/v1",
apiKey: "YOUR_API_KEY",
});
// Test the connection
async function test() {
const completion = await openai.chat.completions.create({
messages: [{ role: "user", content: "Hello!" }],
model: "auto",
});
console.log(completion.choices[0].message.content);
}
test();
Python
Prerequisites
- Python 3.7+
- pip package manager
Install OpenAI SDK
# Using pip
pip install openai
# Using conda
conda install openai
# For development
pip install openai python-dotenv
Basic Setup
import openai
client = openai.OpenAI(
api_key="YOUR_API_KEY",
base_url="https://api.akbxr.com/v1"
)
# Test the connection
response = client.chat.completions.create(
model="auto",
messages=[
{"role": "user", "content": "Hello!"}
]
)
print(response.choices[0].message.content)
Using Environment Variables
import os
from dotenv import load_dotenv
import openai
# Load environment variables from .env file
load_dotenv()
client = openai.OpenAI(
api_key=os.getenv("AI_API_KEY", "YOUR_API_KEY"),
base_url="https://api.akbxr.com/v1"
)
Virtual Environment (Recommended)
# Create virtual environment
python -m venv ai-api-env
# Activate virtual environment
# On macOS/Linux:
source ai-api-env/bin/activate
# On Windows:
ai-api-env\Scripts\activate
# Install dependencies
pip install openai python-dotenv
# Create requirements.txt
pip freeze > requirements.txt
cURL (HTTP Requests)
No installation required! You can use cURL directly:
curl -X POST https://api.akbxr.com/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
-d '{
"model": "auto",
"messages": [
{
"role": "user",
"content": "Hello, AI!"
}
],
"stream": false
}'
Other Languages
PHP
composer require guzzlehttp/guzzle
<?php
require 'vendor/autoload.php';
use GuzzleHttp\Client;
$client = new Client();
$response = $client->post('https://api.akbxr.com/v1/chat/completions', [
'headers' => [
'Authorization' => 'Bearer YOUR_API_KEY',
'Content-Type' => 'application/json',
],
'json' => [
'model' => 'auto',
'messages' => [
['role' => 'user', 'content' => 'Hello!']
]
]
]);
$data = json_decode($response->getBody(), true);
echo $data['choices'][0]['message']['content'];
?>
Go
go mod init ai-api-example
go get github.com/go-resty/resty/v2
package main
import (
"fmt"
"github.com/go-resty/resty/v2"
)
type ChatMessage struct {
Role string `json:"role"`
Content string `json:"content"`
}
type ChatRequest struct {
Model string `json:"model"`
Messages []ChatMessage `json:"messages"`
}
func main() {
client := resty.New()
resp, err := client.R().
SetHeader("Authorization", "Bearer YOUR_API_KEY").
SetHeader("Content-Type", "application/json").
SetBody(ChatRequest{
Model: "auto",
Messages: []ChatMessage{
{Role: "user", Content: "Hello!"},
},
}).
Post("https://api.akbxr.com/v1/chat/completions")
if err != nil {
panic(err)
}
fmt.Println(resp.String())
}
Next Steps
Now that you have the SDK installed:
Ready to make your first API call? Continue to the Quick Start guide.