Errors
An error comes back with an HTTP status code and a JSON body. The body always has a detail key. Most of the time detail is a plain string:
{ "detail": "Link not found" }
Three kinds of error carry more data: plan errors, usage-limit errors and validation errors. They are described below.
Status codes
| Status | Meaning | Example detail |
|---|---|---|
400 | The request is wrong in a way the server checks itself. | "Alias must be 3–32 chars (letters, numbers, - or _)." |
401 | No valid API key or session. | "Invalid API key", "Not authenticated" |
402 | Your plan doesn't include the feature, or you hit a usage limit. | See below |
403 | Signed in, but not allowed: the key lacks a scope, or your team role is too low. | "API key lacks permission: links:write" |
404 | Not found, or not in your workspace. | "Link not found" |
409 | Conflict with existing data. | "Alias already taken" |
413 | The upload is too large. | "CSV too large (max 1MB)" |
422 | The body or query failed validation, or the destination is unsafe. | See below |
429 | Rate limited. | "API key rate limit exceeded (100/min)" |
5xx | Server error. Safe to retry with backoff. |
402: plan required
A feature your plan doesn't include returns a 402. detail stays a string, so code that reads it as text keeps working. Extra keys sit beside it:
{
"detail": "Requires plan: pro or enterprise",
"error": "plan_required",
"message": "Requires plan: pro or enterprise",
"feature": "routing",
"required_plan": "pro",
"plan": "free"
}
| Key | Meaning |
|---|---|
error | Always "plan_required" for this kind of error. |
feature | The feature you tried to use, for example routing, pixels, campaigns. |
required_plan | The cheapest plan that includes the feature. |
plan | Your current plan. A paid plan with an inactive subscription counts as free. |
402: usage limit
When you reach a monthly limit (links, tracked clicks or AI credits), detail is an object:
{
"detail": {
"error": "quota_exceeded",
"message": "You've reached your monthly link limit. Upgrade or buy a link pack to create more.",
"dimension": "links",
"used": 50,
"limit": 50,
"plan": "free",
"upgrade_to": "pro"
}
}
| Key | Meaning |
|---|---|
dimension | What ran out: links, clicks or ai_credits. |
used, limit | Your usage and your limit this month. limit includes packs you bought. |
upgrade_to | The next plan up, or null on Enterprise. |
AI endpoints called on a plan with no AI credits return the same nested shape with "error": "ai_requires_paid_plan".
Check typeof body.detail. A string means a plan error. An object means a usage limit.
422: validation error
A body or query that doesn't match the schema returns FastAPI's standard 422. Here detail is a list, one item per problem:
{
"detail": [
{
"type": "missing",
"loc": ["body", "url"],
"msg": "Field required",
"input": {}
}
]
}
loc points at the field. A destination flagged as phishing or malware also returns 422, but with a string detail.
Handle errors in code
- JavaScript
- Python
const res = await fetch("https://api.linklane.io/api/links", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.LINKLANE_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({ url: "https://example.com" }),
});
if (!res.ok) {
const { detail } = await res.json();
if (Array.isArray(detail)) {
// 422: one entry per invalid field
console.error(detail.map((d) => `${d.loc.join(".")}: ${d.msg}`).join("\n"));
} else if (typeof detail === "object") {
// 402 usage limit
console.error(`${detail.dimension}: ${detail.used}/${detail.limit}`);
} else {
console.error(res.status, detail);
}
}
import os
import requests
res = requests.post(
"https://api.linklane.io/api/links",
headers={"Authorization": f"Bearer {os.environ['LINKLANE_API_KEY']}"},
json={"url": "https://example.com"},
)
if not res.ok:
detail = res.json()["detail"]
if isinstance(detail, list): # 422: one entry per invalid field
for d in detail:
print(".".join(map(str, d["loc"])), d["msg"])
elif isinstance(detail, dict): # 402 usage limit
print(f"{detail['dimension']}: {detail['used']}/{detail['limit']}")
else:
print(res.status_code, detail)