kronoslabs
v1.1.2
Published
Official JavaScript/TypeScript client for Kronos Labs API
Downloads
9
Maintainers
Readme
Kronos Labs JavaScript/TypeScript Client
Official JavaScript/TypeScript client for the Kronos Labs API.
Installation
npm install kronoslabs
# or
yarn add kronoslabsQuick Start
JavaScript (CommonJS)
const { KronosLabs } = require("kronoslabs");
// Initialize the client
const client = new KronosLabs({ apiKey: "your-api-key-here" });
// Non-streaming chat completion
async function chat() {
const response = await client.chat.completions.create({
prompt: "Hello, how are you?",
model: "hyperion", // or "hermes"
temperature: 0.7,
isStream: false,
});
console.log(response.choices[0].message.content);
}
chat();TypeScript
import { KronosLabs } from "kronoslabs";
const client = new KronosLabs({ apiKey: "your-api-key-here" });
async function chat() {
const response = await client.chat.completions.create({
prompt: "Hello, how are you?",
model: "hyperion", // or "hermes"
temperature: 0.7,
isStream: false,
});
console.log(response.choices[0].message.content);
}
chat();Streaming
const client = new KronosLabs({ apiKey: "your-api-key-here" });
async function streamChat() {
const stream = await client.chat.completions.create({
prompt: "Tell me a story",
model: "hyperion", // or "hermes"
temperature: 0.8,
isStream: true,
});
for await (const chunk of stream) {
if (chunk.choices[0]?.delta?.content) {
process.stdout.write(chunk.choices[0].delta.content);
}
}
}
streamChat();Features
- Simple and intuitive API similar to OpenAI's ChatGPT client
- Full TypeScript support with type definitions
- Support for multiple models:
hyperionandhermes - Support for both streaming and non-streaming responses
- Automatic handling of API authentication
- Comprehensive error handling
- Works in Node.js environments
- Tool calling (coming soon)
API Reference
Initialize Client
const client = new KronosLabs({
apiKey: "your-api-key",
baseUrl: "https://kronoslabs.org", // optional
});Chat Completions
const response = await client.chat.completions.create({
messages: [], // Optional: array of message objects
prompt: "Your prompt here", // Required: the prompt text
model: "hermes", // Optional: "hyperion" or "hermes" (default: "hyperion")
temperature: 0.7, // Optional: controls randomness (0.0-2.0)
isStream: false, // Optional: enable streaming
tool: false, // Optional: enable tool usage (Work in Progress - not yet functional)
});Parameters
messages(array, optional): Array of message objects withroleandcontentpropertiesprompt(string, required): The prompt text to send to the modelmodel(string, optional): Model to use - either"hyperion"or"hermes". Default:"hyperion"temperature(number, optional): Controls randomness in the response (0.0-2.0). Default: 0.7isStream(boolean, optional): Enable streaming responses. Default: falsetool(boolean, optional): Work in Progress - Tool calling functionality is currently under development and not yet available. Default: false
Response Format
Non-streaming response:
{
id: string;
object: 'chat.completion';
created: number;
model: string;
choices: [{
index: number;
message: {
role: 'assistant';
content: string;
};
finish_reason: string;
}];
usage: {
prompt_tokens: number;
completion_tokens: number;
total_tokens: number;
};
}Streaming response (async iterable of chunks):
{
id: string;
object: 'chat.completion.chunk';
created: number;
model: string;
choices: [{
index: number;
delta: {
role?: 'assistant';
content?: string;
};
finish_reason: string | null;
}];
}Error Handling
import { KronosLabs, KronosLabsError } from "kronoslabs";
const client = new KronosLabs({ apiKey: "your-api-key" });
try {
const response = await client.chat.completions.create({
prompt: "Hello",
});
} catch (error) {
if (error instanceof KronosLabsError) {
console.error("API error:", error.message);
console.error("Status code:", error.statusCode);
}
}Examples
See the examples directory for more usage examples:
basic-chat.js- Simple non-streaming chatstreaming-chat.js- Streaming responseschat-with-history.js- Maintaining conversation historyerror-handling.js- Handling errors
License
MIT License
