OpenAI SDK
The official OpenAI SDKs, pointed at the RFS Router. Two settings change; nothing else.
The OpenAI SDKs work with every model the RFS Router serves, on Chat Completions and Responses. Change the base URL and the key:
npm i openaiimport OpenAI from "openai";
const ai = new OpenAI({
baseURL: "https://relayfor.si/api/v1",
apiKey: process.env.RELAYFOR_ROUTER_KEY,
});
const reply = await ai.chat.completions.create({
model: "google/gemini-3.8-flash",
messages: [
{ role: "system", content: "You run the $NOVA community. Be brief." },
{ role: "user", content: "Welcome the 1,000th holder in one line." },
],
max_tokens: 256,
});
console.log(reply.choices[0]?.message.content);Streaming
const stream = await ai.chat.completions.create({
model: "anthropic/claude-sonnet-5.5",
messages: [{ role: "user", content: "Draft today's update for holders." }],
max_tokens: 1024,
stream: true,
// The last chunk then carries usage, with what the call cost.
stream_options: { include_usage: true },
});
for await (const chunk of stream) {
process.stdout.write(chunk.choices[0]?.delta?.content ?? "");
}Responses
const response = await ai.responses.create({
model: "openai/gpt-6.1-sol",
instructions: "You are a concise market assistant for a Solana token.",
input: "Summarize: 412 trades today, volume 1,940 SOL, holders up 6%.",
max_output_tokens: 256,
});
console.log(response.output_text);Responses is stateless here: send the conversation as input each time.
What it cost
Every answer's usage.cost is what the call was charged, in dollars. The SDK's types don't name it, but it is there:
const cost = (reply.usage as { cost?: number } | undefined)?.cost;Errors and retries
The SDK raises the router's errors as its own APIError, with status and the router's code. It already retries 429 and 5xx after the wait the router names. See Errors.