JavaScript SDK

Official JavaScript SDK for integrating Bleu.js into your web applications

Installation

npm install @bleujs/sdk

The JavaScript SDK is available as an npm package and can be installed in any Node.js or browser environment.

Quick Start

import { BleuClient } from '@bleujs/sdk'; const client = new BleuClient({ apiKey: 'your-api-key-here' }); // Generate text const response = await client.generate({ prompt: 'Hello, world!', maxTokens: 100 }); console.log(response.text);

Configuration

API Key

Your API key is required for authentication. You can get one from your dashboard.

Base URL

By default, the SDK uses the production API endpoint. You can override this for testing or custom deployments.

Core Methods

generate()

Generate text completions using the Bleu.js AI model.

await client.generate({ prompt: string, maxTokens?: number, temperature?: number, topP?: number })

embed()

Generate embeddings for text input.

await client.embed({ input: string | string[] })

chat()

Have a conversation with the AI model.

await client.chat({ messages: Message[], maxTokens?: number, temperature?: number })

Error Handling

try { const response = await client.generate({ prompt: 'Hello, world!' }); } catch (error) { if (error.code === 'RATE_LIMIT_EXCEEDED') { // Handle rate limiting } else if (error.code === 'INVALID_API_KEY') { // Handle authentication errors } }

Examples

Text Generation

const response = await client.generate({ prompt: 'Write a short story about a robot learning to paint.', maxTokens: 200, temperature: 0.7 }); console.log(response.text);

Chat Conversation

const messages = [ { role: 'user', content: 'What is the capital of France?' } ]; const response = await client.chat({ messages, maxTokens: 100 }); console.log(response.message.content);

Text Embeddings

const embeddings = await client.embed({ input: ['Hello world', 'Goodbye world'] }); console.log(embeddings.data[0].embedding);

SDK Versions

Current1.1.6
LTS1.1.0
Beta1.2.0-beta