Examples
HTTP & JavaScript
These samples mirror the JSON shape our server integration uses: non-streaming chat, bearer auth, and optional routing mode via X-LK-Mode. Replace the host if your workspace uses a custom LatentKit base URL.
cURL
Quick check from any terminal. Export LATENTKIT_KEY first.
curl -sS -X POST "https://ai.latentkit.com/v1/chat" \
-H "Authorization: Bearer $LATENTKIT_KEY" \
-H "Content-Type: application/json" \
-H "X-LK-Mode: priority" \
-d '{
"messages": [
{ "role": "system", "content": "You are a helpful assistant." },
{ "role": "user", "content": "Hello!" }
],
"stream": false
}'Node / Next.js (fetch)
Same request in TypeScript. Run on the server so your API key never ships to the browser.
const res = await fetch("https://ai.latentkit.com/v1/chat", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.LATENTKIT_KEY}`,
"Content-Type": "application/json",
"X-LK-Mode": "priority"
},
body: JSON.stringify({
messages: [
{ role: "system", content: "You are a helpful assistant." },
{ role: "user", content: "Hello!" }
],
stream: false
})
});
if (!res.ok) {
throw new Error(`Request failed: ${res.status}`);
}
const data = await res.json();
console.log(data);