Chat
Text models use the OpenAI chat completions format. Any OpenAI client works: set the base URL to https://api.tovano.ai/v1 and use your Tovano key.
Request
curl https://api.tovano.ai/v1/chat/completions \
-H "Authorization: Bearer $TOVANO_API_KEY" \
-H "Content-Type: application/json" \
-H "X-Tovano-Customer: client-0482" \
-d '{
"model": "text/demo-chat-1",
"messages": [
{ "role": "system", "content": "You write short ad copy." },
{ "role": "user", "content": "Three captions for a mug ad" }
]
}'With an OpenAI client
import OpenAI from "openai";
const client = new OpenAI({
baseURL: "https://api.tovano.ai/v1",
apiKey: process.env.TOVANO_API_KEY,
});
const stream = await client.chat.completions.create({
model: "text/demo-chat-1",
messages: [{ role: "user", content: "Three captions for a mug ad" }],
stream: true,
});
for await (const chunk of stream) process.stdout.write(chunk.choices[0]?.delta?.content ?? "");Streaming
With "stream": true the reply comes as server-sent events, one data: line per piece, and ends with data: [DONE]. The last chunk before [DONE] carries usage and the charge:
{
"usage": { "prompt_tokens": 42, "completion_tokens": 61, "total_tokens": 103 },
"tovano": { "task_id": "tsk_c81d...", "charged_micro": 58 }
}Charges
You pay for input tokens at the model's input price and output tokens at its output price. charged_micro: 58 above is $0.000058. Every chat call is recorded as a task, so it shows up in Tasks and Usage.