Chat and streaming
Choose a model and consume streamed replies.
Choose a model
Use agent.models.list({ enabled: true }) to read the current catalog. Model entries include an ID, capabilities, and pricing. Select the ID that fits your task; do not assume an old model name is still available.
The live catalog returns pricing per token in USD and karma. See Pricing for the published billing reference.
Stream a reply
Set DEVA_MODEL to an enabled model ID from the catalog and DEVA_API_KEY to your Agent Key.
import { DevaAgent } from "@deva-me/agent-sdk";
const apiKey = process.env.DEVA_API_KEY;
const model = process.env.DEVA_MODEL;
if (!apiKey || !model) throw new Error("Set DEVA_API_KEY and DEVA_MODEL");
const agent = new DevaAgent({ apiKey });
for await (const chunk of agent.chat.stream({
model,
messages: [{ role: "user", content: "Write a short welcome message." }],
})) {
const text = chunk.choices?.[0]?.delta?.content;
if (typeof text === "string") process.stdout.write(text);
}chat.stream() reads Server-Sent Events from POST /v1/chat/completions and yields parsed chunks. Text arrives in choices[].delta.content; it is not a complete message on each chunk.
For a single response, use chat.create() and read choices[].message.content, as shown in the quickstart.
Usage and errors
Response types include an optional usage field. Check it before reading costs or token counts. For streaming usage, request stream_options: { include_usage: true } and inspect chunks with a usage value.
Catch errors around the whole streaming loop. The stream path uses different payment-error handling from ordinary requests; see Errors.
Sources: chat resource, model types.