REST API
One endpoint. Send a question, get back a verified answer and the lines it came from.
Set this up with your AI agent
Add Docket's REST API to this project's server code.
Docket answers questions from my own documents and returns the answer with the lines it came from. It is hosted at https://YOUR_HOST. Docs: https://YOUR_HOST/docs?page=rest-api
What to do
1. Look at the project first: the language, the framework, and where server code and HTTP calls live. If something important is unclear, ask me one short question before you change anything.
2. Write one server-side function, for example askDocket(question), that sends:
POST https://YOUR_HOST/api/v1/query
Authorization: Bearer <secret key>
Content-Type: application/json
{ "query": "<the question>" }
and returns reply, verified and citations from the JSON response. Each citation has file, startLine, endLine and verified.
3. Read the key from an environment variable named DOCKET_API_KEY. Add DOCKET_API_KEY= (empty) to .env.example and make sure .env is listed in .gitignore. Do not ask me to paste the key into this chat: I will add it to my .env file myself.
4. If the app has a user interface, expose the function through the app's own server endpoint and have the frontend call that. The key must stay on the server.
5. Show reply to the user. When verified is false, reply already holds a safe fallback message, so it can be shown as it is.
6. Handle errors. 401 with code UNAUTHORIZED means the key is wrong or revoked. 429 means a rate limit: wait the number of seconds in the Retry-After header and retry once. For any other failure, show a short message, not a stack trace.
7. Check it works once the key is set: call the function with a question my documents answer (for example "What is the refund policy?") and print reply and citations. If I have not set the key yet, tell me what to add and stop there.
Rules
- Use a secret key. It starts with sk_live_ and I create it in Studio: open the group, go to Keys, choose Secret.
- Never put the secret key in code, in a browser bundle, in a log or in a commit.
- Each request is independent: the endpoint does not remember earlier questions, and it returns the answer in one piece, not streamed.
When you finish, list the files you changed. Do not change anything unrelated.Endpoint
POST https://YOUR_HOST/api/v1/queryEach request is independent: the endpoint does not remember earlier questions, and answers are returned in one piece, not streamed.
Authentication
Send your key in the Authorization header. Use a secret key (sk_live_…) from your server and never ship it to a browser. See API keys.
Authorization: Bearer sk_live_YOUR_SECRET_KEYThe X-API-Key header, or an apiKey field in the body, is accepted as well.
Request
Send a JSON body with a Content-Type: application/json header.
| Field | Type | Description |
|---|---|---|
query | string | Required. The question to answer. You can also send it as message. |
apiKey | string | Optional. Your key, if you cannot set a header. |
curl https://YOUR_HOST/api/v1/query \ -H "Authorization: Bearer $DOCKET_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "query": "What is the refund policy?" }'Response
A successful call returns 200.
{ "success": true, "query": "What is the refund policy?", "reply": "Pro plans can be refunded within 30 days of purchase.", "verified": true, "verificationScore": 100, "citations": [ { "file": "billing/refunds.md", "startLine": 12, "endLine": 14, "verified": true } ], "latencyMs": 1180, "meta": { "groupId": "js74eds1zfddpvp9nr4mnmf1zd8j93d9", "keyType": "secret", "costUSD": 0.0008, "remainingBalanceUSD": 24.99, "blockedByGuardrail": false }}| Field | Description |
|---|---|
reply | The answer to show your user. When it could not be verified this is your fallback message. |
verified | True when the answer passed verification. |
verificationScore | Score from 0 to 100. An answer is verified when it reaches the group’s threshold. |
citations | Where the answer comes from: file, startLine, endLine, and whether that citation checked out. |
latencyMs | Time taken to produce the answer, in milliseconds. |
meta.costUSD | Credits charged for this request. |
meta.remainingBalanceUSD | Credits left after this request. |
meta.blockedByGuardrail | True when the question was refused before any answer was written. |
When credits run out
With a zero balance the call still returns200, with verified set to false and a reply that says answers are paused. Top up in Studio to resume.Rate limits
Requests are limited per key, per caller IP address and per day, so one caller cannot use up a key and a leaked key can only be used at a bounded rate. Bursts are allowed: the numbers below are the sustained rate, and the burst is how many requests can be made back to back.
| Limit | Publishable key | Secret key |
|---|---|---|
| Per IP address, on one key | 30 per minute, burst 10 | 240 per minute, burst 60 |
| Per IP address, across all keys | 60 per minute, burst 20 | No limit |
| Per key, all callers together | 120 per minute, burst 40 | 600 per minute, burst 150 |
| Per key, per day | 5,000 | 50,000 |
When a limit is reached the API answers 429 and tells you when to try again. Wait that long, then retry, and add some jitter if many workers share a key. Repeating the request at once only keeps it refused.
HTTP/1.1 429 Too Many RequestsRetry-After: 2RateLimit-Limit: 30RateLimit-Remaining: 0RateLimit-Reset: 2RateLimit-Policy: 30;w=60
{ "success": false, "error": "Too many requests from your network. Please try again in 2 seconds.", "code": "RATE_LIMITED", "scope": "ip_key", "retryAfterSeconds": 2}| Header | Meaning |
|---|---|
Retry-After | Seconds to wait before the next request. |
RateLimit-Limit | Requests allowed per window by the limit that was reached. |
RateLimit-Remaining | Always 0 on a 429. |
RateLimit-Reset | Seconds until the limit resets. |
Too many invalid keys
An address that sends ten invalid or unauthorized keys in ten minutes is refused for the rest of that period, withscope set to auth, even if its next request is valid.Errors
Errors return success: false and a readable error message.
| Status | Meaning |
|---|---|
400 | The body has no query. |
401 | The key is invalid, deactivated, or not allowed from this origin. The body also carries code UNAUTHORIZED. |
429 | A rate limit was reached. Wait for Retry-After seconds. The body carries code RATE_LIMITED. |
500 | Something went wrong on our side. Retry after a moment. |
{ "success": false, "error": "Invalid API key or workspace token", "code": "UNAUTHORIZED"}Health check
GET /api/v1/query needs no key and returns the service status, which makes it a convenient check that your host is reachable.