Using the API
SlashAPI follows the OpenAI chat completions format. If your code already talks to OpenAI, you change the address and the key and keep everything else.
Quick start
- Create an account and add a balance from $10.
- Create an API key in your dashboard. It is shown once, so copy it somewhere safe.
- Point your client at SlashAPI and pick a model name from the price list.
from openai import OpenAIclient = OpenAI(base_url="https://slashapi.dev/api/public/v1",api_key="sk-slash-...",)reply = client.chat.completions.create(model="MODEL_ID",messages=[{"role": "user", "content": "Hello"}],)print(reply.choices[0].message.content)
API keys
Send your key with every request in the Authorization header as Bearer sk-slash-.... Keys start with sk-slash-.
You can make a separate key for each app or teammate and revoke any of them from the dashboard; a revoked key stops working straight away. We keep only a scrambled fingerprint of each key, so a lost key cannot be shown again. Make a new one instead.
Chat completions
POST /chat/completions takes a model and a non-empty messages list. Other OpenAI options you send, such as temperature or max_tokens, are passed on to the model.
curl https://slashapi.dev/api/public/v1/chat/completions \-H "Authorization: Bearer sk-slash-..." \-H "Content-Type: application/json" \-d '{"model": "MODEL_ID","messages": [{"role": "system", "content": "You are a helpful assistant."},{"role": "user", "content": "Hello"}]}'
The reply has the usual OpenAI shape, including a usage block with the prompt and completion token counts you were charged for.
Streaming
Add "stream": true and the reply arrives piece by piece as server-sent events, ending with data: [DONE]. The final piece before that carries the token usage for the request.
curl -N https://slashapi.dev/api/public/v1/chat/completions \-H "Authorization: Bearer sk-slash-..." \-H "Content-Type: application/json" \-d '{"model": "MODEL_ID", "stream": true,"messages": [{"role": "user", "content": "Hello"}]}'
List models
GET /models returns every model you can call with its current price per million tokens. It needs no key, so you can read prices before you sign up.
curl https://slashapi.dev/api/public/v1/models
{"object": "list","data": [{"id": "MODEL_ID","object": "model","owned_by": "Maker","context_length": 1000000,"pricing": {"currency": "USD","input_per_million": 1.7,"output_per_million": 8.5}}]}
Models that charge more for very long prompts also include above_prompt_tokens with the length where the higher price starts and the prices that then apply.
Billing
Each request costs its prompt tokens at the model's input price plus its completion tokens at the output price. The cost is taken from your prepaid balance when the request finishes and listed on your usage page.
A request is accepted while your balance is above zero. At zero, requests return 402 insufficient_balance until you top up. Nothing is charged to your card automatically.
Errors
Errors use the OpenAI format, with a short code you can check in your own code.
{"error": {"message": "Your balance is empty. Add funds in the dashboard to continue.","type": "insufficient_balance","param": null,"code": "insufficient_balance"}}
| Status | Code | What it means |
|---|---|---|
| 400 | invalid_json | The request body is not valid JSON. |
| 400 | invalid_request | The model or the messages list is missing or empty. |
| 401 | invalid_api_key | The key is missing, wrong or has been revoked. |
| 402 | insufficient_balance | Your balance is empty. Add funds to continue. |
| 404 | model_not_found | That model name is not on the price list. |
| 413 | request_too_large | The request body is too big. |
| 400–429 | upstream_rejected | The model refused the request, for example a prompt that is too long or too many requests at once. The message says why. |
| 502 | upstream_error | The model failed or could not be reached. Try again. |
| 503 | service_unavailable | SlashAPI is temporarily unavailable. Try again shortly. |
Ready to send your first request?
Get an API key