Skip to main content
// Non-streaming
const res = await naive.llm.chat({
  model: "anthropic/claude-sonnet-4.6",
  messages: [{ role: "user", content: "Hello" }],
  models: ["anthropic/claude-sonnet-4.6", "openai/gpt-5.2"], // optional fallback chain
  provider: { sort: "throughput", data_collection: "deny" }, // optional OpenRouter routing
});
res.choices[0].message.content;
res.credits_used;

// Streaming (SSE) — yields OpenAI-compatible chunks
for await (const chunk of naive.llm.stream({ model: "openai/gpt-5.2", messages })) {
  process.stdout.write(chunk.choices[0]?.delta?.content ?? "");
}

// List models (free) + per-generation stats
const { models } = await naive.llm.models("claude");
const stats = await naive.llm.generation("gen-xxxx");
The request/response shapes are OpenRouter’s (OpenAI-compatible) — see the LLM primitive guide and OpenRouter’s API reference. Billed in Naive credits from OpenRouter’s returned usage.cost. Per-user and AccountKit-gated like other primitives (naive.forUser(id).llm).
Prefer the drop-in proxy (baseURL: https://api.usenaive.ai/v1/proxy/openrouter) if you want to keep using the OpenAI/OpenRouter SDK unchanged. See LLM → Use Naive instead of OpenRouter.