Errors and rate limits
The API answers with standard HTTP status codes and a JSON body that explains the error.
Error format
{
"error": "q must contain 3–120 characters"
}
Status codes
| Code | Meaning |
|---|---|
200 |
Success. |
400 |
A parameter is missing or invalid; the message says which. |
401 |
The key is missing, malformed, revoked or expired. |
403 |
The key does not permit this search. |
404 |
Unknown endpoint, or a record the source no longer publishes. |
429 |
Rate limit exceeded. |
503 |
Temporarily unavailable. |
Rate limits
Each key can make 300 requests per minute, and an aggregate limit protects the service for everyone. Responses over the limit answer 429 with a Retry-After header in seconds.
Retries
Retry 429 and 503 after the number of seconds in Retry-After, with a bounded number of attempts. Do not retry other 4xx errors: the request needs to change.
async function medifontis(path, params, attempts = 3) {
for (let attempt = 1; ; attempt++) {
const response = await fetch(`https://api.medifontis.com${path}?${new URLSearchParams(params)}`, {
headers: { Authorization: `Bearer ${process.env.MEDIFONTIS_API_KEY}` },
})
if (response.ok) return response.json()
if (![429, 503].includes(response.status) || attempt === attempts) {
throw new Error(`Medifontis ${response.status}: ${(await response.json()).error}`)
}
const seconds = Number(response.headers.get('retry-after')) || 2 ** attempt
await new Promise(resolve => setTimeout(resolve, seconds * 1000))
}
}
Caching
Responses carry Cache-Control: no-store. If you store results in your own system, keep their retrievedAt and refresh them with GET /v1/drugs/record.