# MaddLabs documentation

MaddLabs (https://maddlabs.co) is an inference API for open-weight language models. It is compatible with the OpenAI Chat
Completions API, so existing OpenAI SDKs work after changing the base URL and the key. Models run on GPUs in the
European Economic Area. Prompts and completions are never stored. Billing is prepaid: you top up credit and each
request is charged per token.

- Base URL: `https://maddlabs.co/v1`
- Dashboard (keys, usage, billing, limits, team): https://maddlabs.co/app
- Status and uptime: https://maddlabs.co/status
- Support: support@maddlabs.co

## Models and prices

Prices are in USD per 1 million tokens. This table is generated live from the catalog.

| Model | ID | Context | Max output | Input | Input $/1M | Cached $/1M | Output $/1M | Quantization | Hosted in | Status |
|---|---|---|---|---|---|---|---|---|---|---|
| Qwen4-35B-A3B | `qwen/qwen4-35b-a3b` | 1,048,576 | 32,768 | text, image, video | 0.35 | 0.0875 | 2.8 | fp8 | CZ | online |
| Bielik 11B v3 | `speakleash/bielik-11b-v3.0-instruct` | 32,768 | 8,192 | text | 0.06 | 0.015 | 0.24 | int4 | PL | temporarily offline |

- **Qwen4-35B-A3B** (`qwen/qwen4-35b-a3b`, Alibaba Qwen, license Apache 2.0): Newest open-weight multimodal Mixture-of-Experts model from Qwen (released December 2026): 35B parameters with about 3B active, 1M-token context. Accepts text, images and video. Fast, strong at agentic tasks, tools and Polish. Replaces Qwen3.8 27B: requests for qwen/qwen3.8-27b are served by this model. Answers without thinking by default; turn thinking on with reasoning.enabled=true.
- **Bielik 11B v3** (`speakleash/bielik-11b-v3.0-instruct`, SpeakLeash, license Apache 2.0): Polish-first 11B instruct model by SpeakLeash and ACK Cyfronet AGH, trained on a large curated Polish corpus. Natural, fluent Polish for chat, writing, summarisation and question answering. Runs on MaddLabs hardware in Poland.

Cached input is prefix caching done automatically by the server: a repeated prompt prefix is billed at the cached
price. There is nothing to configure. The same list in JSON: `GET https://maddlabs.co/v1/models` (no key needed), one model:
`GET https://maddlabs.co/v1/models/{id}`.

## Quickstart

1. Create an account at https://maddlabs.co/signup (email code, Google or Apple).
2. Top up credit at https://maddlabs.co/app/billing.
3. Create an API key at https://maddlabs.co/app/keys. The key is shown once.
4. Call the API:

```bash
curl https://maddlabs.co/v1/chat/completions \
  -H "Authorization: Bearer $MADDLABS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model": "qwen/qwen4-35b-a3b", "messages": [{"role": "user", "content": "Hello"}]}'
```

```python
from openai import OpenAI
client = OpenAI(base_url="https://maddlabs.co/v1", api_key="sk-madd-...")
r = client.chat.completions.create(model="qwen/qwen4-35b-a3b", messages=[{"role": "user", "content": "Hello"}])
print(r.choices[0].message.content)
```

## Authentication and API keys

Send the key as a bearer token: `Authorization: Bearer sk-madd-...`. Keys are stored only as a hash.
A key can be limited to chosen models, to IP addresses or CIDR ranges, to a monthly budget in USD and to an
expiration date. A leaked key can be rotated (new secret, same settings and history) or revoked.

`GET https://maddlabs.co/v1/key` returns the state of the calling key: balance, spend this month, remaining budget, restrictions
and rate limits.

## Endpoints

- `POST /v1/chat/completions`: chat completions, OpenAI compatible, streaming and non-streaming.
- `GET /v1/models`, `GET /v1/models/{id}`: catalog with prices, context length and readiness.
- `GET /v1/key`: state of the calling key.

Supported request parameters: `model`, `messages`, `stream`, `max_tokens` (or `max_completion_tokens`),
`temperature`, `top_p`, `top_k`, `min_p`, `stop`, `seed`, `frequency_penalty`, `presence_penalty`,
`repetition_penalty`, `logit_bias`, `logprobs`, `top_logprobs`, `n` (up to 8), `tools`, `tool_choice`,
`parallel_tool_calls`, `response_format` (`text`, `json_object`, `json_schema`), `reasoning`, `include_reasoning`.
`max_tokens` above the model's maximum output is clamped to that maximum.

Images and video (models that list them as input) are sent as OpenAI content parts with a public `http(s)` URL
or a base64 `data:` URL.

## Reasoning

`"reasoning": {"enabled": true}` or `"reasoning": {"effort": "low" | "medium" | "high"}` turns thinking on.
`"reasoning": {"enabled": false}` or effort `none` turns it off. Without the field the model's default applies
(the models above answer without thinking by default). Thinking is returned in `message.reasoning`
(`delta.reasoning` when streaming). `"reasoning": {"exclude": true}` keeps it out of the response.

## Streaming

With `"stream": true` the response is server-sent events: `data: {...}` chunks ending with `data: [DONE]`.
The last chunk carries `usage`. A stream interrupted by the client is billed for the tokens generated so far.
Non-streaming responses that take longer than about 20 seconds send whitespace before the JSON body to keep the
connection alive; JSON parsers ignore it.

## Cost in the response

Every successful response includes `usage.prompt_tokens`, `usage.completion_tokens`,
`usage.prompt_tokens_details.cached_tokens` and `usage.cost` (USD charged for this request).

## Errors

Errors use the OpenAI shape: `{"error": {"message": "...", "type": "...", "code": "..."}}`.

| HTTP | code | Meaning |
|---|---|---|
| 400 | (various) | Invalid request, unknown model, `unsupported_modality`, `invalid_media_url` |
| 401 | | Missing or invalid API key |
| 402 | `insufficient_credits` | Balance is zero or below the estimated prompt cost |
| 402 | `promo_model_only` | Free trial or bonus tokens apply only to promotion models; this model needs a balance |
| 402 | `trial_daily_limit` | Free trial: today's free token allowance is used up and the balance is zero (resets 00:00 UTC) |
| 403 | `model_not_allowed`, `ip_not_allowed`, `region_not_allowed`, `account_suspended` | Key restriction, the account's allowed processing countries (Data controls) or suspended account |
| 429 | `rate_limit_exceeded` | Account rate limit, see `Retry-After` and `x-ratelimit-*` headers |
| 429 | `budget_exceeded`, `account_budget_exceeded` | Monthly budget of the key or the account reached |
| 429 | | Model capacity reached, retry shortly |
| 502 | | Model backend error |
| 503 | `model_disabled` | Model temporarily offline |

Every response has an `X-Request-Id` header. Quote it when contacting support.

## Rate limits

Limits depend on the total amount topped up. They apply per account in a sliding 60 second window.

| Tier | Total top-ups from | Requests / min | Tokens / min | Parallel requests |
|---|---|---|---|---|
| Free | $0 | 20 | 40,000 | 2 |
| Tier 1 | $5 | 60 | 200,000 | 8 |
| Tier 2 | $50 | 300 | 1,000,000 | 24 |
| Tier 3 | $250 | 1,000 | 3,000,000 | 48 |
| Tier 4 | $1,000 | 3,000 | 10,000,000 | 96 |

Responses carry `x-ratelimit-limit-requests`, `x-ratelimit-remaining-requests`, `x-ratelimit-limit-tokens`,
`x-ratelimit-remaining-tokens` and reset headers, as in the OpenAI API.

## Billing

- Prepaid credit kept in USD. Top up by card through Stripe in USD, EUR or PLN (5 to 5,000 USD, 5 to 5,000 EUR, 20 to 20,000 PLN net per top-up).
  EUR and PLN are converted at the average rate of the National Bank of Poland.
- VAT: 23% for buyers in Poland and for EU buyers without a verified VAT ID; 0% reverse charge for EU businesses
  with a VAT ID confirmed in VIES; 0% outside the EU. A VAT invoice is issued for each top-up.
- Optional automatic top-up from a saved card when the balance falls below a threshold.
- Budgets: a monthly limit per key and a monthly spend limit for the whole account. Email alerts for low balance
  and for monthly spend.
- Credit does not expire. Closing the account returns the unused balance on request.
- Teams: invite members with roles (owner, admin, developer, billing, viewer) to share one account.

## Data handling

- Zero data retention: prompts and completions are processed in memory and never written to disk or logs.
  Only billing metadata is stored: time, model, token counts, cost, status, latency.
- Models run in the European Economic Area. The country of each model is in the table above.
- Details: https://maddlabs.co/legal/data-policy, https://maddlabs.co/legal/privacy, https://maddlabs.co/legal/dpa, https://maddlabs.co/legal/subprocessors.

## Company

MaddLabs is operated by MADD Marcin Kisielinski, ul. Kajki 10-12, 10-547 Olsztyn, Poland, VAT ID PL7422297084.
Terms of Service: https://maddlabs.co/legal/terms. Security contact: https://maddlabs.co/.well-known/security.txt.
