SDK & Integration

Read your help center from your own AI assistant

Mis à jour 224 vues

Your help center is already a curated, deduplicated, human-edited knowledge base. If you are building an assistant of your own — a support copilot, an internal Slack bot, an agent inside your product — you can read from it directly rather than keeping a second copy of the same text in a vector database and remembering to sync it.

Three additions in @kookee/sdk 1.8.0 make that practical: a relevance score on search hits, Markdown bodies on reads, and an opt-in for articles written for an assistant rather than for people.

If you just want an assistant on your site, you do not need any of this — install the built-in one instead. This page is for the case where the model, the prompt and the conversation are yours.

The whole pattern

Search for candidates, read the best one, answer from it:

TypeScript
import { Kookee } from '@kookee/sdk';

const kookee = new Kookee({ apiKey: process.env.KOOKEE_API_KEY, timeoutMs: 10_000 });

async function contextFor(question: string): Promise<string | null> {
  const hits = await kookee.help.search({ query: question, limit: 5, includeChatbotOnly: true });

  const [best] = hits.filter((hit) => hit.score === null || hit.score > 0.6);
  if (!best) return null;

  const article = await kookee.help.getById(best.id, { markdown: true, includeChatbotOnly: true });
  return (article.contentMarkdown ?? '').slice(0, 8_000);
}

Everything below is the detail behind those three lines.

score — how well it matched

Search is semantic: it embeds the query and compares it against every chunk of every published article. score is the cosine similarity of the chunk that matched best, and matchedChunk is that chunk's text.

TypeScript
const hits = await kookee.help.search({ query: 'stop charging me', limit: 5 });

hits.forEach((hit) => {
  hit.title;
  hit.score;        // 0.4 – 1, or null
  hit.matchedChunk; // the passage behind that score, or null
});

Hits below 0.4 are never returned, so every number you see is between 0.4 and 1. What the numbers mean in practice:

  • Above ~0.7 — the article is about the question.

  • 0.5 to 0.7 — related, often the right answer expressed differently.

  • Below 0.5 — the same general area. Worth showing a human, usually not worth feeding a model.

Those bands are a starting point, not a law. Tune them against your own articles, because similarity depends on how you write.

null means the search fell back to text matching. When the embedding service is unavailable, or no passage scores 0.4 or more, the query falls back to a plain title-and-body match, which has no score and is ordered by publication date rather than relevance. Treating null as zero would silently drop every result of a degraded search; the snippet above lets those through instead.

markdown — fewer tokens than HTML

Reads return contentHtml, which is what you want for a page and wasteful for a prompt: tags, classes and attributes cost tokens and tell a model nothing. Pass markdown: true and you also get contentMarkdown:

TypeScript
const article = await kookee.help.getById(id, { markdown: true });

article.contentHtml;     // always there
article.contentMarkdown; // headings, lists, tables and code as Markdown

It is the same rendering the export endpoint has always produced, so it round-trips: an article authored in the dashboard comes back as clean Markdown. contentMarkdown is null when the article has no body, and the key is absent entirely unless you asked for it — nothing changes for existing callers.

Both help.getById() and help.getBySlug() take it, as do the generic entries methods.

includeChatbotOnly — articles written for an assistant

An article's visibility can be Chatbot only. Those articles stay out of your help center's listings, sitemap, RSS and llms.txt, but the built-in assistant reads them. It is the right home for an escalation matrix, a troubleshooting decision tree, or the long factual reference nobody wants on a public page.

By default they are invisible to the API too. includeChatbotOnly: true lets your own assistant read what the built-in one reads:

TypeScript
const hits = await kookee.help.search({ query, includeChatbotOnly: true });
const article = await kookee.help.getById(id, { includeChatbotOnly: true });

It applies to search and to single-article reads. Listings, exports, sitemaps and llms.txt ignore it, which is what keeps those articles unlisted.

Chatbot-only means unlisted, not secret. Anyone holding your API key can read those articles with this flag, and your key is public if you also run the chat widget — the widget ships it in the page. Do not put anything in a chatbot-only article that you would not say to a customer who asked the right question.

timeoutMs — because fetch has no deadline

Node's fetch waits forever by default. On a server that means one hung connection can pin a request handler until something else gives up:

TypeScript
const kookee = new Kookee({ apiKey: process.env.KOOKEE_API_KEY, timeoutMs: 10_000 });

Every read gets that deadline and rejects with a TimeoutError when it passes. A call you give your own AbortSignal stops at whichever comes first, your abort or the deadline. help.chat() and help.chatStream() are never timed out — an answer legitimately takes as long as it takes. To stop a stream, abort it:

TypeScript
const controller = new AbortController();
for await (const chunk of kookee.help.chatStream({ messages }, controller.signal)) {
  // controller.abort() ends the answer and stops the server generating the rest
}

What it costs

Every search and every read is one API request. Both count against your account's monthly API quota — shared across all of that account's projects — and against the project's per-minute rate limit.

An assistant answering one question therefore spends two or three requests, and the per-minute limit is what you will hit first if you fan out searches. Exceeding either returns 429 with the code MONTHLY_API_LIMIT_EXCEEDED or RATE_LIMIT_EXCEEDED. Your plan's numbers are on the dashboard — see Rate limits, plans and error handling.

Cache aggressively. Article bodies change when someone edits them, not per request — see Caching strategies for Kookee content.

Over plain HTTP

No SDK required:

Bash
curl -H "Kookee-API-Key: YOUR_API_KEY" \
  "https://api.kookee.dev/v1/help/search?query=reset+password&limit=5&includeChatbotOnly=true"

curl -H "Kookee-API-Key: YOUR_API_KEY" \
  "https://api.kookee.dev/v1/entries/by-id/ARTICLE_ID?markdown=true&includeChatbotOnly=true"

Note the second URL: single-article reads go to the generic entry endpoints, /v1/entries/:slug and /v1/entries/by-id/:id. That is where the SDK's help.getById() and help.getBySlug() send them, and it is the path to reach for.

Or let the built-in assistant do it

If what you actually want is a support assistant on your site, the built-in one already does all of the above — plus tool calling, page context, citations and conversation storage — with one script tag. See Install the site widget on your website.

Available in @kookee/sdk and @kookee/react 1.8.0 and later. Before 1.10.1, a call given its own AbortSignal was not timed out at all.

Cet article vous a-t-il aidé ?