@yavqo/aisdk
v1.0.2
Published
Official Yavqo AI SDK for Node.js — powered by Sunlight AI. First-class support for Sunlight 2 and Sunlight 2 Pro.
Maintainers
Readme
@yavqo/aisdk
Official Yavqo AI SDK for Node.js — powered by Sunlight AI.
Installable via:
npm install @yavqo/aisdk
# or
pnpm add @yavqo/aisdk
# or
yarn add @yavqo/aisdkProvides first-class support for:
- Sunlight 2 — fast, efficient coding model
- Sunlight 2 Pro — frontier reasoning model
Quick Start
import { createYavqo, sunlight2, sunlight2Pro } from '@yavqo/aisdk';
// Zero-config — works out of the box
const yavqo = createYavqo();
// Simple prompt
const { text } = await yavqo.generateText({
model: sunlight2,
prompt: 'Write a hello world in TypeScript',
});
console.log(text);
// With system + messages
const { text: text2 } = await yavqo.generateText({
model: sunlight2Pro,
system: 'You are a helpful coding assistant.',
messages: [{ role: 'user', content: 'Explain closures in JS' }],
temperature: 0.7,
maxTokens: 1024,
});Streaming
import { createYavqo, sunlight2Pro } from '@yavqo/aisdk';
const yavqo = createYavqo();
const { textStream, final } = await yavqo.streamText({
model: sunlight2Pro,
prompt: 'Write a short story about a robot learning to paint',
});
for await (const delta of textStream) {
process.stdout.write(delta);
}
const result = await final;
console.log('\n---\nUsage:', result.usage);Chat completions
import { Yavqo, sunlight2 } from '@yavqo/aisdk';
const client = new Yavqo();
const completion = await client.chat.completions.create({
model: sunlight2,
messages: [
{ role: 'system', content: 'You are Sunlight, a helpful AI.' },
{ role: 'user', content: 'Hello!' },
],
temperature: 0.7,
});
console.log(completion.choices[0].message.content);Structured output (JSON) — with Zod validation
import { createYavqo, sunlight2 } from '@yavqo/aisdk';
import { z } from 'zod';
const yavqo = createYavqo();
// Option A: raw JSON Schema
const { object } = await yavqo.generateObject<{ name: string; age: number }>({
model: sunlight2,
prompt: 'Generate a person with name and age',
schema: {
type: 'object',
properties: {
name: { type: 'string' },
age: { type: 'number' },
},
required: ['name', 'age'],
additionalProperties: false,
},
schemaName: 'person',
});
console.log(object); // { name: "Alice", age: 30 }
// Option B: Zod schema — validated locally
const Person = z.object({ name: z.string(), age: z.number() });
const { object: person } = await yavqo.generateObject({
model: sunlight2,
prompt: 'Generate a person',
schema: Person,
});
console.log(person);Tools / Function calling
const { text, toolCalls } = await yavqo.generateText({
model: sunlight2Pro,
messages: [{ role: 'user', content: 'What is the weather in Tokyo?' }],
tools: [
{
type: 'function',
function: {
name: 'get_weather',
description: 'Get weather for a city',
parameters: {
type: 'object',
properties: { city: { type: 'string' } },
required: ['city'],
},
},
},
],
});API Reference
createYavqo(config?) / new Yavqo(config?)
interface YavqoConfig {
apiKey?: string; // optional — defaults to built-in key
baseURL?: string; // optional — defaults to Sunlight AI gateway
headers?: Record<string, string>;
fetch?: typeof fetch;
timeoutMs?: number; // default 60_000 (0 = no timeout)
maxRetries?: number; // default 2
retry?: {
maxRetries?: number;
initialDelayMs?: number;
maxDelayMs?: number;
backoffFactor?: number;
jitter?: boolean;
retryStatusCodes?: number[];
};
}Models
import { sunlight2, sunlight2Pro } from '@yavqo/aisdk';
sunlight2 // Sunlight 2
sunlight2Pro // Sunlight 2 ProMethods
| Method | Description |
|--------|-------------|
| yavqo.generateText(opts) | Non-streaming text generation |
| yavqo.streamText(opts) | Streaming generation |
| yavqo.generateObject(opts) | JSON object generation (with optional schema) |
| yavqo.chat.completions.create(opts) | Low-level chat completions |
| yavqo.chat.completions.stream(opts) | Low-level streaming |
| yavqo.listModels() | List available models |
Common options
{
model: string; // required
prompt?: string;
system?: string;
messages?: ChatMessage[];
temperature?: number;
top_p?: number;
maxTokens?: number;
tools?: Tool[];
tool_choice?: ToolChoice;
stop?: string | string[];
responseFormat?: { type: 'text' | 'json_object' | 'json_schema' };
headers?: Record<string, string>;
extraBody?: Record<string, unknown>;
signal?: AbortSignal;
maxRetries?: number;
retry?: RetryConfig;
}Retry & backoff
Automatic retry for transient failures (429, 500, 502, 503, 504, 529) with exponential backoff + jitter and Retry-After support.
const yavqo = createYavqo({
maxRetries: 3,
retry: { initialDelayMs: 300, maxDelayMs: 5000, backoffFactor: 2 },
});CJS + ESM
// ESM
import { createYavqo } from '@yavqo/aisdk';
// CJS
const { createYavqo } = require('@yavqo/aisdk');Testing
npm test
npm run lintTypeScript
Fully typed. Requires Node >= 18.
License
MIT © Yavqo
