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: "gpt-6-astra",
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: "gpt-6-astra",
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 prompt prefix byte-identical across calls: same text, same order.
- Pass a stable prompt_cache_key string. It is a routing-affinity hint; it does not create or identify cached content.
- Check usage.prompt_tokens_details.cached_tokens in the response to confirm cache reads.
{
"model": "gpt-4o",
"prompt_cache_key": "v1-stable-prefix",
"messages": [{ "role": "user", "content": "..." }]
}{
"model": "gpt-4o",
"prompt_cache_key": "v1-stable-prefix",
"messages": [{ "role": "user", "content": "..." }]
}