OpenAI-compatible TypeScript/JavaScript client for the MyAi decentralized compute network.
npm install @myai/sdk openai
# or
yarn add @myai/sdk openaiimport { MyAi } from "@myai/sdk";
const client = new MyAi({ apiKey: "myai_..." }); // or set MYAI_API_KEY
const response = await client.chat.completions.create({
model: "qwen2.5-14b-awq",
messages: [{ role: "user", content: "Hello!" }],
});
console.log(response.choices[0].message.content);Any code that uses the openai npm package works with @myai/sdk — just swap the import.
const models = await client.models.list();
for await (const model of models) {
console.log(model.id);
}const result = await client.embeddings.create({
model: "nomic-embed-text",
input: "The quick brown fox",
});
console.log(result.data[0].embedding.slice(0, 5));const stream = await client.chat.completions.create({
model: "qwen2.5-14b-awq",
messages: [{ role: "user", content: "Count to 5" }],
stream: true,
});
for await (const chunk of stream) {
process.stdout.write(chunk.choices[0]?.delta?.content ?? "");
}| Variable | Description |
|---|---|
MYAI_API_KEY |
Your MyAi API key |
MYAI_BASE_URL |
Override endpoint (default: https://api.myaitoken.io/v1) |
Full types are included — no @types/ package needed.
import { MyAi } from "@myai/sdk";
import type { ChatCompletion } from "openai/resources";
const client = new MyAi();
const response: ChatCompletion = await client.chat.completions.create({
model: "qwen2.5-14b-awq",
messages: [{ role: "user", content: "Hello" }],
});