import OpenAI from "openai";
const openai = new OpenAI({
baseURL: "https://api.inference.net/v1",
apiKey: "<YOUR_API_KEY>",
});
const completion = await openai.chat.completions.create({
model: "claude-opus-4-6",
messages: [
{
role: "user",
content: "What is the meaning of life?"
}
],
stream: true,
});
for await (const chunk of completion) {
process.stdout.write(chunk.choices[0]?.delta.content as string);
}import OpenAI from "openai";
const openai = new OpenAI({
baseURL: "https://api.inference.net/v1",
apiKey: "<YOUR_API_KEY>",
});
const completion = await openai.chat.completions.create({
model: "claude-opus-4-6",
messages: [
{
role: "user",
content: "What is the meaning of life?"
}
],
stream: true,
});
for await (const chunk of completion) {
process.stdout.write(chunk.choices[0]?.delta.content as string);
}Prompt caching
- Keep the stable system content block byte-identical across calls.
- Mark it with cache_control: { "type": "ephemeral" } to set a cache point.
- Check usage.prompt_tokens_details.cached_tokens in the response to confirm cache reads. Initial writes may appear in cache-creation usage fields.
{
"messages": [{
"role": "system",
"content": [{
"type": "text",
"text": "Stable system content...",
"cache_control": { "type": "ephemeral" }
}]
}]
}{
"messages": [{
"role": "system",
"content": [{
"type": "text",
"text": "Stable system content...",
"cache_control": { "type": "ephemeral" }
}]
}]
}