meganova
v0.3.0
Published
Official JavaScript SDK for MegaNova AI — Inference, Cloud Agents, and Agent SDK
Maintainers
Readme
MegaNova JavaScript SDK
Official JavaScript/TypeScript SDK for the MegaNova AI platform — inference, cloud agents, and more.
Installation
npm install meganovaRequires Node.js 18+ (uses native fetch).
Quick Start
Chat Completion
import { MegaNova } from "meganova";
const client = new MegaNova({ apiKey: "YOUR_API_KEY" });
const response = await client.chat.completions.create({
messages: [
{ role: "system", content: "You are a helpful assistant." },
{ role: "user", content: "What is the capital of France?" },
],
model: "meganova-ai/manta-flash-1.0",
});
console.log(response.choices[0].message.content);Streaming
const stream = await client.chat.completions.create({
messages: [{ role: "user", content: "Write a haiku about space." }],
model: "meganova-ai/manta-flash-1.0",
stream: true,
});
for await (const chunk of stream) {
const content = chunk.choices[0]?.delta?.content;
if (content) process.stdout.write(content);
}Cloud Agents
Chat with deployed MegaNova Studio agents using just an API key — no authentication setup required.
import { CloudAgent } from "meganova";
const agent = new CloudAgent({ apiKey: "agent_xxx..." });
// Get agent info
const info = await agent.info();
console.log(`${info.name}: ${info.welcome_message}`);
// Chat
const response = await agent.chat("Hello!");
console.log(response.response);Multi-turn Conversation
const conv = agent.conversation();
const r1 = await conv.chat("I need help with my account");
const r2 = await conv.chat("My email is [email protected]");
// conversation_id is tracked automaticallyTool Confirmation
Some agents use tools (ticket creation, email, etc.) that require approval:
const conv = agent.conversation();
const response = await conv.chat("Create a support ticket for my login issue");
if (conv.pendingToolCall) {
console.log(`Agent wants to: ${conv.pendingToolCall.description}`);
const result = await conv.confirm(); // or conv.reject()
}OpenAI-compatible Completions
// Non-streaming
const response = await agent.completions({
messages: [{ role: "user", content: "Hello!" }],
});
console.log(response.choices[0].message.content);
// Streaming
const stream = await agent.completions({
messages: [{ role: "user", content: "Tell me a story" }],
stream: true,
});
for await (const chunk of stream) {
const content = chunk.choices[0]?.delta?.content;
if (content) process.stdout.write(content);
}Image Generation
const response = await client.images.generate({
prompt: "A futuristic city skyline at sunset, digital art",
model: "ByteDance/SeedDream-4-5",
width: 1024,
height: 1024,
});
// response.data[0].b64_json contains the base64-encoded imageModel Discovery
// List all models
const models = await client.models.list();
// List serverless models with pricing
const textModels = await client.serverless.listModels("text_generation");
for (const model of textModels.models) {
console.log(`${model.model_name}: $${model.cost_per_1k_input}/1K input`);
}
// Image models
const imageModels = await client.serverless.listModels("text_to_image");Supported Models
- Text:
meganova-ai/manta-mini-1.0,manta-flash-1.0,manta-pro-1.0,Qwen/Qwen3-235B-A22B-Instruct-2507 - Image:
ByteDance/SeedDream-4-5,black-forest-labs/FLUX.1-dev - Audio:
Systran/faster-whisper-large-v3 - Vision:
Qwen/Qwen2.5-VL-7B-Instruct
Use client.serverless.listModels() for the full list with pricing.
Error Handling
import { MeganovaError, AuthenticationError, RateLimitError } from "meganova";
try {
await client.chat.completions.create({ ... });
} catch (err) {
if (err instanceof AuthenticationError) {
console.error("Invalid API key");
} else if (err instanceof RateLimitError) {
console.error("Rate limited, retry later");
} else if (err instanceof MeganovaError) {
console.error(`API error (${err.status}): ${err.message}`);
}
}Configuration
const client = new MegaNova({
apiKey: "YOUR_API_KEY",
baseUrl: "https://api.meganova.ai/v1", // default
timeout: 60000, // ms, default 60s
maxRetries: 2, // default
});Environment variable: set MEGANOVA_API_KEY and read it in your app.
Examples
See the examples/ directory for runnable scripts.
License
MIT
