Raw HTTP

Calling the API directly with curl, fetch or requests — no SDK required.

On this page

curl

bash
curl https://api.apione.ai/v1/chat/completions \
  -H "Authorization: Bearer $APIONE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "deepseek-v4-flash",
    "messages": [{ "role": "user", "content": "Hello" }],
    "max_tokens": 256
  }'

Python requests

python
import os, requests

r = requests.post(
    "https://api.apione.ai/v1/chat/completions",
    headers={
        "Authorization": "Bearer " + os.environ["APIONE_API_KEY"],
        "Content-Type": "application/json",
    },
    json={
        "model": "deepseek-v4-flash",
        "messages": [{"role": "user", "content": "Hello"}],
    },
    timeout=60,
)
r.raise_for_status()
print(r.json()["choices"][0]["message"]["content"])

fetch (Node / edge runtimes)

javascript
const r = await fetch("https://api.apione.ai/v1/chat/completions", {
  method: "POST",
  headers: {
    Authorization: "Bearer " + process.env.APIONE_API_KEY,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    model: "deepseek-v4-flash",
    messages: [{ role: "user", content: "Hello" }],
  }),
});
if (!r.ok) throw new Error(await r.text());
const data = await r.json();
console.log(data.choices[0].message.content);

Parsing the stream by hand

javascript
const r = await fetch("https://api.apione.ai/v1/chat/completions", {
  method: "POST",
  headers: {
    Authorization: "Bearer " + process.env.APIONE_API_KEY,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({ model: "gemini-3.5-flash", stream: true,
                         messages: [{ role: "user", content: "Tell me a dry joke" }] }),
});

const reader = r.body.getReader();
const decoder = new TextDecoder();
let buffer = "";

while (true) {
  const { done, value } = await reader.read();
  if (done) break;
  buffer += decoder.decode(value, { stream: true });

  const lines = buffer.split("\n");
  buffer = lines.pop() ?? "";          // the last line may be partial — keep it
  for (const line of lines) {
    if (!line.startsWith("data: ")) continue;
    const payload = line.slice(6).trim();
    if (payload === "[DONE]") continue;
    const delta = JSON.parse(payload).choices?.[0]?.delta?.content;
    if (delta) process.stdout.write(delta);
  }
}
Warning

Always keep the trailing partial buffer when splitting on newlines. Network chunks do not align to line boundaries, so parsing each chunk directly fails intermittently — the classic hand-rolled-SSE bug.

Contact us

Something unclear, or need a human? Pick the channel that fits your question.