<!-- Generated from https://qnepal.com/docs at build time. -->

# Build with QNepal

QNepal speaks the OpenAI and Anthropic wire formats, so the official SDKs work unchanged. Just swap the base URL and the key.

## Authentication

Create a key on the [API keys](https://qnepal.com/app/keys) page. Send it as `Authorization: Bearer qn-…` (OpenAI style) or `x-api-key: qn-…` (Anthropic style).

## OpenAI-compatible endpoints

Base URL `https://api.qnepal.com/v1`. Supported: `POST /v1/chat/completions`, `POST /v1/responses`, `POST /v1/embeddings` and `GET /v1/models`. Streaming works as usual. For streamed chat completions we always request a final usage chunk, so your stream ends with a chunk where `choices` is empty.

Claude models also work on `/v1/chat/completions`, so an OpenAI-SDK app can switch to Claude by changing only the model name. On that route Claude returns one choice (`n` must be 1), prompt caching is not available, and file inputs are not supported. Use `/v1/messages` for those.

curl

```bash
curl https://api.qnepal.com/v1/chat/completions \
  -H "Authorization: Bearer $QNEPAL_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model":"gpt-6.2-sol","messages":[{"role":"user","content":"नमस्ते"}]}'
```

## Anthropic-compatible endpoints

Point the Anthropic SDK at `https://api.qnepal.com` (no `/v1`; the SDK adds it). Supported: `POST /v1/messages` (streaming included) and `POST /v1/messages/count_tokens`. `anthropic-version` and `anthropic-beta` headers are passed through.

Python

```python
import anthropic
client = anthropic.Anthropic(base_url="https://api.qnepal.com", api_key="qn-…")
msg = client.messages.create(model="claude-opus-5-5", max_tokens=1024,
    messages=[{"role": "user", "content": "Hello"}])
```

## What's supported

Everything below works with the official SDKs unchanged. Anything not listed is refused with a clear error rather than silently ignored.

| Feature | Where | Billing |
| --- | --- | --- |
| Streaming, tools / function calling, structured outputs, vision, PDFs | All generation endpoints | Tokens |
| Extended thinking / reasoning effort | /v1/messages, /v1/responses, /v1/chat/completions | Thinking counts as output tokens |
| Prompt caching: cache_control (automatic or breakpoints, 5m / 1h) | /v1/messages | Cache writes 1.25× / 2×, reads ~0.1× input |
| Prompt caching: automatic, prompt_cache_key, prompt_cache_options.ttl 30m / 12h | /v1/responses, /v1/chat/completions | Cache writes at the provider's rate, reads at the cached rate |
| Web search tool (web_search_*) | /v1/messages (Claude) | $10 per 1,000 searches + result tokens; max_uses 5 by default (max 10); prompts up to ~100K tokens |
| Web fetch tool (web_fetch_*) | /v1/messages (Claude) | Tokens only; max_uses 5 (max 10), max_content_tokens 25K (max 50K) |
| Web search tool (web_search) | /v1/responses (OpenAI) | $10 per 1,000 searches + result tokens; max_tool_calls 10 by default (max 20); web_search_preview isn't accepted |
| Conversation state: previous_response_id; GET/DELETE /v1/responses/{id}; …/input_items | /v1/responses | Free; only your own responses are visible |
| Message Batches (create, get, list, results, cancel, delete) | /v1/messages/batches (Claude) | 50% off tokens; failed, cancelled or expired requests are free |
| Token counting | /v1/messages/count_tokens, /v1/responses/input_tokens | Free |
| Moderation | /v1/moderations | Free after your first top-up (60/min) |
| Embeddings | /v1/embeddings | Input tokens |
| Model list / details | GET /v1/models, GET /v1/models/{id} | Free; OpenAI and Anthropic SDK shapes |

**Not yet:** code execution and hosted containers, file search and vector stores, the Files API and OpenAI's Batch API (it needs Files), MCP connectors, background responses, image, audio and realtime APIs. These either store objects in a shared account or are billed in ways we can't attribute fairly per customer yet.

**Caching tips:** your cache is private to your account (and to your team), even though the providers' caches are shared per organisation. Put stable instructions and documents first. On OpenAI you may set your own `prompt_cache_key` to spread busy traffic; we keep it inside your account's namespace. Requests that may write to the cache reserve credit at the cache-write rate, and you're charged what was actually used.

**Batches:** each request is reserved at batch prices when you submit, and billed when the batch ends (usually within an hour, at most 24). Up to 10,000 requests per batch (100 until your first top-up). Deleting a batch first bills it, so finish reading results before you delete.

## Fair use & limits

Every customer shares the same provider capacity, so a few limits keep it fair. They are generous for normal use, and every limited response is a standard `429` with a `Retry-After` header that the official SDKs already respect.

- **Per key:** requests per minute (120 by default, adjustable per key).
- **Per account:** up to 16 requests in flight and about 2M tokens a minute. Each request counts its prompt plus its `max_tokens`, so asking for less output leaves more room.
- **New accounts** (no top-up yet): 30 requests a minute, 4 at a time and 200K tokens a minute. These lift automatically after your first top-up.

OpenAI and Anthropic run safety systems on every request. If your requests are repeatedly refused or flagged, we first lower your limits and email you, and pause API access only if it continues. A person reviews every case. If your work legitimately involves sensitive topics (safety research, moderation tools), tell us in advance at [support@qnepal.com](mailto:support@qnepal.com). We record that a request was refused, never what it said. For new accounts, prompts sent to OpenAI models also get a background check with OpenAI's moderation model. It never blocks or delays a request, and nothing is stored.

## Billing & limits

- Each request is charged from the provider-reported token counts, including cached input and cache writes, in NPR.
- Before forwarding, we briefly reserve the maximum the request could cost (from `max_tokens`, capped at 32K). The unused part is released right away. If the reserve is more than your balance you'll get `402 insufficient_quota`; lower `max_tokens` or top up.
- Default rate limit: 120 requests per minute per key. Over the limit you get `429` with `Retry-After`.
- Every response has an `X-Request-Id`. Include it when contacting support.

## Privacy

We don't store prompts or completions. We keep request metadata (model, token counts, latency, cost) for billing. Requests are processed by OpenAI or Anthropic under their API data policies.

## Not supported yet

OpenAI's Files and Batch APIs (Claude Message Batches are supported, see above), assistants, vector stores, fine-tuning, realtime/audio, image generation, and the Responses API `background`, `conversation` and stored `prompt` features. `previous_response_id` works for responses created with your own account.

## Quick reference

- **OpenAI SDK:** `base_url="https://api.qnepal.com/v1"`, key in `Authorization: Bearer qn-…`
- **Anthropic SDK:** `base_url="https://api.qnepal.com"`, key in `x-api-key: qn-…`
- **Model names:** use the `id` values from `GET https://api.qnepal.com/v1/models`. It needs no key and also returns each model's context window and price in NPR per million tokens.
- **Currency:** all charges are in Nepali rupees (NPR), taken from your prepaid wallet.
- **Errors** use the provider's shape: `{"error":{"message","type","code"}}` on OpenAI-style endpoints and `{"type":"error","error":{"type","message"}}` on `/v1/messages`.

| Status | Type | Meaning |
| --- | --- | --- |
| 400 | invalid_request_error | The request body or a parameter is not accepted. |
| 401 | authentication_error | Missing, invalid, expired or revoked API key. |
| 402 | insufficient_quota | Balance (or the key's spend limit) can't cover the request's reserve. Lower max_tokens or top up. |
| 403 | permission_error | The key or account may not do this: a model outside the key's allowed list, a paused key, or access paused for safety review. |
| 404 | not_found_error | Unknown model or resource. GET /v1/models lists the models you can use. |
| 413 | invalid_request_error | Request body too large. |
| 429 | rate_limit_error | Over a rate or concurrency limit. Wait for Retry-After; the official SDKs do this. |
| 502 / 503 / 504 | api_error | Provider unavailable, interrupted request or temporary error. The message says what, if anything, was charged. Retry with backoff. |

**Machine-readable:** [llms.txt](https://qnepal.com/llms.txt), [llms-full.txt](https://qnepal.com/llms-full.txt), this page as [Markdown](https://qnepal.com/docs.md), and an [OpenAPI description](https://qnepal.com/openapi.json) of the endpoints.
