@paxsenix/ai
Version:
A lightweight and intuitive Node.js client for the Paxsenix AI API.
186 lines (140 loc) β’ 4.57 kB
Markdown
# @paxsenix/ai
A lightweight and intuitive Node.js client for the [Paxsenix AI API](https://api.paxsenix.biz.id/docs).
Easily integrate AI-powered chat completions, streaming responses, model listing, and moreβright into your app.
**Free to use with a rate limit of 3 requests per minute.**
Need more? API key support with higher limits! :)





## π Table of Contents
- [Features](#-features)
- [Installation](#-installation)
- [Usage](#-usage)
- [Initialize the Client](#initialize-the-client)
- [Chat Completions](#chat-completions)
- [Streaming Chat Completions](#streaming-chat-completions)
- [List Available Models](#list-available-models)
- [Error Handling](#οΈ-error-handling)
- [Rate Limits](#-rate-limits)
- [Upcoming Features](#-upcoming-features)
- [License](#-license)
- [Feedback & Contributions](#-feedback--contributions)
## π Features
- **Chat Completions** β Generate AI-powered responses with ease
- **Streaming Responses** β Get output in real-time as the AI types
- **Model Listing** β Retrieve available model options
- **Planned** β Image generation, embeddings, and more (coming soon)
## π¦ Installation
```bash
npm install @paxsenix/ai
```
## π Usage
### Initialize the Client
```js
import PaxSenixAI from '@paxsenix/ai';
// Without API key (free access)
const paxsenix = new PaxSenixAI();
// With API key
const paxsenix = new PaxSenixAI('YOUR_API_KEY');
// Advanced usage
const paxsenix = new PaxSenixAI('YOUR_API_KEY', {
timeout: 30000, // Request timeout in ms
retries: 3, // Number of retry attempts
retryDelay: 1000 // Delay between retries in ms
});
```
### Chat Completions (Non-Streaming)
```js
const response = await paxsenix.createChatCompletion({
model: 'gpt-3.5-turbo',
messages: [
{ role: 'system', content: 'You are a sarcastic assistant.' },
{ role: 'user', content: 'Wassup beach' }
],
temperature: 0.7,
max_tokens: 100
});
console.log(response.choices[0].message.content);
console.log('Tokens used:', response.usage.total_tokens);
```
Or using resource-specific API:
```js
const chatResponse = await paxsenix.Chat.createCompletion({
model: 'gpt-3.5-turbo',
messages: [
{ role: 'system', content: 'You are a sarcastic assistant.' },
{ role: 'user', content: 'Who tf r u?' }
]
});
console.log(chatResponse.choices[0].message.content);
```
### Chat Completions (Streaming)
```js
// Simple callback approach
await paxsenix.Chat.streamCompletion({
model: 'gpt-3.5-turbo',
messages: [{ role: 'user', content: 'Hello!' }]
}, (chunk) => console.log(chunk.choices[0]?.delta?.content || '')
);
// With error handling
await paxsenix.Chat.streamCompletion({
model: 'gpt-3.5-turbo',
messages: [
{ role: 'user', content: 'Hello!' }
]
}, (chunk) => console.log(chunk.choices[0]?.delta?.content || ''),
(error) => console.error('Error:', error),
() => console.log('Done!')
);
// Using async generator (recommended)
for await (const chunk of paxsenix.Chat.streamCompletionAsync({
model: 'gpt-3.5-turbo',
messages: [
{ role: 'user', content: 'Hello!' }
]
})) {
const content = chunk.choices?.[0]?.delta?.content;
if (content) process.stdout.write(content);
}
```
### List Available Models
```js
const models = await paxsenix.listModels();
console.log(models.data);
```
## π οΈ Error Handling
```js
try {
const response = await paxsenix.createChatCompletion({
model: 'gpt-3.5-turbo',
messages: [{ role: 'user', content: 'Hello!' }]
});
} catch (error) {
console.error('Status:', error.status);
console.error('Message:', error.message);
console.error('Data:', error.data);
}
```
## β±οΈ Rate Limits
- Free access allows up to **3 requests per minute**.
- Higher rate limits and API key support are planned.
- API keys will offer better stability and priority access.
## π§ Upcoming Features
- **Image Generation**
- **Embeddings Support**
## π License
MIT License. See [LICENSE](LICENSE) for full details. :)
## π¬ Feedback & Contributions
Pull requests and issues are welcome.
Feel free to fork, submit PRs, or just star the repo if it's helpful :P