JavaScript / TypeScript
The official TypeScript client, @miriel/miriel, wraps the REST API for Node and other server-side JavaScript runtimes. It ships its own type definitions.
bash
npm install @miriel/miriel # or: yarn add @miriel/mirieltypescript
import { Miriel } from "@miriel/miriel";
const m = new Miriel({
apiKey: process.env.MIRIEL_API_KEY!, // required
// baseUrl: "https://api.miriel.ai", // optional
});Server-side only
The client sends your account key. Run it in Node, a server route or a worker — never in code shipped to browsers. Front-end apps should call your own backend, which calls Miriel.
learn takes a string or an array of strings: text, URLs, file paths or directories (paths are uploaded). Options are positional; pass undefined to skip one.
typescript
learn(
input: string | string[],
userId?, metadata?, forceString = false, discoverable = true, grantIds = ["*"],
domainRestrictions?, recursionDepth = 0, priority: number | "pin" | "norank" = 100,
project?, waitForComplete = false, chunkSize?, pollingInterval?,
command?: "add" | "upsert" | "append", upsertIds?: string[], expirationSeconds?,
)typescript
// Text, with metadata, into a project, and wait until it is searchable
await m.learn(
"Runbook: reset the primary database by …",
undefined,
{ doc_type: "runbook", team: "eng" }, // metadata
true, // forceString: never treat it as a path
true, ["*"], undefined, 0, 100,
"eng_docs", // project
true, // waitForComplete
);
// Several URLs at once, then wait for exactly those jobs
const { job_ids } = await m.learn(["https://example.com/a.pdf", "https://example.com/b.pdf"]);
await m.waitForJobs(job_ids, 2);typescript
query(
query: string,
userId?, inputImages?, responseFormat?, metadataQuery?,
wantLlm = true, wantVector = true, wantGraph = true,
conversationMode?, conversationHistory?: ConversationTurn[],
)typescript
// Filter by metadata
const r = await m.query("How do I reset the database?", undefined, undefined, undefined,
"doc_type=runbook AND team=eng");
console.log(r.results.llm_result);
// Structured output
const s = await m.query("Who founded Miriel?", undefined, undefined,
{ founders: ["string"], number_of_founders: "integer" });
const data = JSON.parse(s.results.llm_result);
// Conversation
import type { ConversationTurn } from "@miriel/miriel";
let history: ConversationTurn[] = [];
const a = await m.query("What is our refund policy?", undefined, undefined, undefined, undefined,
true, true, true, true, history);
history = a.results.conversation_history ?? [];Project scope and num_results
The JS client's
query() does not take project or num_results yet. Until it does, call the REST endpoint directly when you need them — it is one fetch:typescript
const res = await fetch("https://api.miriel.ai/api/v2/query/", {
method: "POST",
headers: { "x-access-token": process.env.MIRIEL_API_KEY!, "Content-Type": "application/json" },
body: JSON.stringify({ query: "What did we decide about pricing?", project: ["default"], num_results: 5 }),
});
const { results } = await res.json();| Method | Does |
|---|---|
| learn(...) | Add text, URLs, files or directories |
| query(...) | Ask a question; returns { results: { llm_result, vector_db_results, … } } |
| waitForJobs(jobIds, pollingInterval?) | Resolve when those learn jobs complete |
| getLearningJobs() / countNonCompletedLearningJobs() | Inspect the ingest queue |
| getQueryResult(queryId) | Fetch a stored (or exhaustive, still-running) query |
| getAllDocuments(userId?, project?, metadataQuery?) | List resources |
| getDocumentById(id) / updateDocument(id, …) | Read or re-tag one resource |
| removeResource(id) / removeAllDocuments(userId?, project?) | Forget |
| getProjects() / createProject(name) / deleteProject(id) | Projects |