sven. API
API

API documentation

Run chat, embedding and image models over HTTP. If you already use an OpenAI client, change its base URL and key and keep the rest of your code; Anthropic's client works for chat too.

Quickstart

Create a key in your account under API keys. It is shown once, so copy it then. Send it as Authorization: Bearer, as the OpenAI clients do, or as x-api-key, as the Anthropic clients do. A key belongs to the account it was created under, and every call made with it is that account's usage. Revoking a key stops it working within seconds.

Pick a model from the pricing page, then call it.

curl
curl https://sven.swedishembedded.com/v1/chat/completions \
  -H "Authorization: Bearer $SVEN_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model": "MODEL", "messages": [{"role": "user", "content": "Hello"}]}'
OpenAI client (Python)
import os
from openai import OpenAI

client = OpenAI(base_url="https://sven.swedishembedded.com/v1", api_key=os.environ["SVEN_API_KEY"])
reply = client.chat.completions.create(
    model="MODEL",
    messages=[{"role": "user", "content": "Hello"}],
)
print(reply.choices[0].message.content)

Streaming

Set stream to true and the reply arrives as server-sent events, exactly as the OpenAI client expects. If the connection drops, the reply still runs to its end and you are charged for what it produced; send the same request again with the same Idempotency-Key header to receive the whole answer without being charged again (while it is still running, the retry is answered 409: try again shortly).

Billing

You pay for what a call delivered, at the prices on the pricing page: per token for chat, per input token for embeddings, per image for images. Before a call starts, the most it could cost is set aside from your account's credit, so a call your credit cannot cover is refused up front rather than failing halfway. When it finishes you are charged for what it actually used and the rest is available again.

Errors

  • 400 The request is malformed, or sets a parameter the model does not accept (the error names it), or a conversation longer than the model can serve.
  • 401 No key, or a key that is unknown, expired or revoked.
  • 402 The account's credit, the key's spending limit or the workspace's monthly budget does not cover what this call could cost. The error code says which; retrying will not help until it does.
  • 403 This key is restricted to other models.
  • 404 No such model. A model that exists but has no price is also absent: it is not for sale.
  • 409 A call with this Idempotency-Key is still running (retry shortly), or its stored answer has expired.
  • 413 The request body is past the size ceiling.
  • 429 Too many calls at once or per minute, or the model is busy. Retry after the Retry-After header's seconds.
  • 500 Something failed inside the service. The response says nothing about internals. Retrying is safe but may fail again.
  • 503 The model is temporarily unavailable. Retry shortly.

Reference

The full description of every route is available as OpenAPI, for generating a client.