Documentation

Chat

Chat completions, supported parameters, and streaming.

POST /chat/completions uses the familiar chat-completions shape. Pick a chat model id from Models.

Supported parameters

model messages temperature top_p max_tokens max_completion_tokens stream stream_options stop presence_penalty frequency_penalty seed user

Anything else is rejected with 400 unsupported_parameter. For example tools and response_format are not supported yet. Message roles are system, developer, user and assistant. stop takes a string or up to 4 strings. temperature is 0 to 2. Up to 500 messages and 400,000 characters of input.

SDK compatibility: OpenAI-compatible for the parameters listed; other parameters are rejected.

curl

curl https://api.billionairestechnologies.com/api/v1/chat/completions \
  -H "Authorization: Bearer $FRIDAY_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model":"bt-spark","messages":[{"role":"user","content":"Summarise this ticket"}]}'

Python

import os
from openai import OpenAI

client = OpenAI(base_url="https://api.billionairestechnologies.com/api/v1", api_key=os.environ["FRIDAY_API_KEY"])

reply = client.chat.completions.create(
    model="bt-spark",
    messages=[{"role": "user", "content": "Summarise this ticket"}],
)
print(reply.choices[0].message.content)

JavaScript

const res = await fetch("https://api.billionairestechnologies.com/api/v1/chat/completions", {
  method: "POST",
  headers: {
    Authorization: "Bearer " + process.env.FRIDAY_API_KEY,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    model: "bt-spark",
    messages: [{ role: "user", content: "Summarise this ticket" }],
  }),
});
const data = await res.json();
console.log(data.choices[0].message.content, res.headers.get("x-friday-cost-paise"));

Streaming

Set stream: true. The response is server-sent events of chat.completion.chunk objects. The last chunk has a finish_reason, a usage object and a friday billing object, followed by [DONE]. Every chunk keeps a choices array, so standard SDK stream parsers work unchanged. Billing settles when the stream ends; if the client disconnects, you are charged for what was produced.

curl -N https://api.billionairestechnologies.com/api/v1/chat/completions \
  -H "Authorization: Bearer $FRIDAY_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model":"bt-spark","stream":true,"messages":[{"role":"user","content":"Write a haiku"}]}'

data: {"object":"chat.completion.chunk","choices":[{"index":0,"delta":{"content":"..."},"finish_reason":null}]}
data: {"object":"chat.completion.chunk","choices":[{"index":0,"delta":{},"finish_reason":"stop"}],"usage":{...},"friday":{"requestId":"req_...","mode":"live","chargedPaise":3,"balancePaise":4997,"priceVersion":1,"usageBasis":"reported"}}
data: [DONE]
import os
from openai import OpenAI

client = OpenAI(base_url="https://api.billionairestechnologies.com/api/v1", api_key=os.environ["FRIDAY_API_KEY"])

stream = client.chat.completions.create(
    model="bt-spark",
    messages=[{"role": "user", "content": "Write a haiku"}],
    stream=True,
)
for chunk in stream:
    if chunk.choices and chunk.choices[0].delta.content:
        print(chunk.choices[0].delta.content, end="")
const res = await fetch("https://api.billionairestechnologies.com/api/v1/chat/completions", {
  method: "POST",
  headers: {
    Authorization: "Bearer " + process.env.FRIDAY_API_KEY,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({ model: "bt-spark", stream: true, messages: [{ role: "user", content: "Write a haiku" }] }),
});
const reader = res.body.getReader();
const decoder = new TextDecoder();
let buffer = "";
for (;;) {
  const { value, done } = await reader.read();
  if (done) break;
  buffer += decoder.decode(value, { stream: true });
  const lines = buffer.split("\n");
  buffer = lines.pop();
  for (const line of lines) {
    if (!line.startsWith("data: ")) continue;
    const data = line.slice(6);
    if (data === "[DONE]") continue;
    const chunk = JSON.parse(data);
    if (chunk.friday) console.log("\nbilling", chunk.friday);
    else if (chunk.error) console.error(chunk.error);
    else process.stdout.write(chunk.choices?.[0]?.delta?.content ?? "");
  }
}