Skip to main content

Chat completions

client.chat.complete() sends a single request and resolves with the full response.

Basic usage​

const response = await client.chat.complete({
model: 'auto',
messages: [
{ role: 'system', content: 'You are a helpful assistant.' },
{ role: 'user', content: 'Explain quantum computing in one sentence.' },
],
});

console.log(response.choices[0].message.content);

Parameters​

ParameterTypeRequiredDescription
modelstringYesauto for automatic selection by Artemis Task (auto-artemis-task and auto-v2 mean the same), or a specific model identifier, e.g. gpt-4o, claude-sonnet-4-6
messagesChatMessage[]YesConversation history
temperaturenumberNoSampling temperature 0–2
maxTokensnumberNoMaximum tokens in the response. Over a project policy's max_tokens limit, the request is refused with 400; left out, the project's limit applies
providerstringNoForce a specific provider, e.g. openai, anthropic. No router runs: with model: 'auto' the provider serves the first model it lists
routerRouterChoice ('artemis' | 'v2')NoNot needed: Artemis Task decides every model: 'auto' request, so both values change nothing. Sent as the x-nuroute-router header; any other value is rejected with a NuRouteError whose status is 400

With model: 'auto', Artemis Task picks the model and the provider. If it cannot decide, fallback-router:apollo does, and the request log says why (Which router decided). A request that names a model uses no router.

Targeting a specific provider​

By default NuRoute selects the provider according to your routing configuration. You can pin a request to a provider:

const response = await client.chat.complete({
model: 'claude-haiku-4-5-20251001',
messages: [{ role: 'user', content: 'Hello!' }],
provider: 'anthropic',
});

Multi-turn conversations​

const messages: ChatMessage[] = [
{ role: 'system', content: 'You are a helpful assistant.' },
];

async function chat(userMessage: string) {
messages.push({ role: 'user', content: userMessage });

const response = await client.chat.complete({ model: 'auto', messages });
const reply = response.choices[0].message;

messages.push(reply);
return reply.content;
}

console.log(await chat('What is 2 + 2?'));
console.log(await chat('And multiply that by 10?'));

Response shape​

The SDK returns the response body only; the gateway's X-Router-* headers are not exposed. To see which router decided, use the request log (Which router decided).

{
id: 'chatcmpl-…',
object: 'chat.completion',
model: 'gpt-4o-mini',
choices: [
{
index: 0,
message: { role: 'assistant', content: '…' },
finish_reason: 'stop',
},
],
usage: {
prompt_tokens: 10,
completion_tokens: 42,
total_tokens: 52,
},
}