{"openapi":"3.1.0","info":{"title":"QLK API","version":"1.0.0","description":"QLK is a URL shortening service built to work with AI agents. Agents can create and manage links, read link analytics, and read every link. Full guide: https://qlk.app/docs.md"},"servers":[{"url":"https://qlk.app/api/v1"}],"security":[{"apiKey":[]}],"paths":{"/links":{"get":{"operationId":"listLinks","summary":"List links, newest first","parameters":[{"name":"limit","in":"query","required":false,"description":"Page size, 1-100.","schema":{"default":20,"type":"integer","minimum":1,"maximum":100}},{"name":"cursor","in":"query","required":false,"description":"`next_cursor` from the previous page.","schema":{"type":"string"}},{"name":"search","in":"query","required":false,"description":"Match against slug, URL or title.","schema":{"type":"string","minLength":1,"maxLength":100}}],"responses":{"200":{"description":"A page of links","content":{"application/json":{"schema":{"type":"object","properties":{"links":{"type":"array","items":{"$ref":"#/components/schemas/Link"}},"next_cursor":{"type":["string","null"],"description":"Pass as `cursor` for the next page."}}}}}},"400":{"description":"Invalid request","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"401":{"description":"Missing or invalid API key","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}},"post":{"operationId":"createLink","summary":"Create a short link","requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/CreateLink"}}}},"responses":{"201":{"description":"The new link","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Link"}}}},"400":{"description":"Invalid request","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"401":{"description":"Missing or invalid API key","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"409":{"description":"Slug is in use","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}}},"/links/{link}":{"parameters":[{"name":"link","in":"path","required":true,"description":"Link id (lnk_...) or slug.","schema":{"type":"string"}}],"get":{"operationId":"getLink","summary":"Get a link","responses":{"200":{"description":"The link","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Link"}}}},"400":{"description":"Invalid request","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"401":{"description":"Missing or invalid API key","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"404":{"description":"No such link","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}},"patch":{"operationId":"updateLink","summary":"Update a link","requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/UpdateLink"}}}},"responses":{"200":{"description":"The updated link","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Link"}}}},"400":{"description":"Invalid request","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"401":{"description":"Missing or invalid API key","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"404":{"description":"No such link","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}},"delete":{"operationId":"deleteLink","summary":"Delete a link and its click history","responses":{"200":{"description":"Deleted","content":{"application/json":{"schema":{"type":"object","properties":{"id":{"type":"string"},"deleted":{"type":"boolean"}}}}}},"400":{"description":"Invalid request","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"401":{"description":"Missing or invalid API key","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"404":{"description":"No such link","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}}},"/links/{link}/stats":{"parameters":[{"name":"link","in":"path","required":true,"description":"Link id (lnk_...) or slug.","schema":{"type":"string"}}],"get":{"operationId":"getLinkStats","summary":"Click analytics for a link","parameters":[{"name":"days","in":"query","required":false,"description":"Look-back window in days, 1-365.","schema":{"default":30,"type":"integer","minimum":1,"maximum":365}}],"responses":{"200":{"description":"Analytics","content":{"application/json":{"schema":{"$ref":"#/components/schemas/LinkStats"}}}},"400":{"description":"Invalid request","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"401":{"description":"Missing or invalid API key","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"404":{"description":"No such link","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}}}},"components":{"securitySchemes":{"apiKey":{"type":"http","scheme":"bearer","description":"API key from the dashboard, starts with qlk_."}},"schemas":{"CreateLink":{"type":"object","properties":{"url":{"type":"string","maxLength":2048,"description":"Destination URL the short link redirects to (http or https)."},"slug":{"type":"string","pattern":"^[A-Za-z0-9][A-Za-z0-9_-]{2,31}$","description":"Custom path for the short link. Omit to get a generated one."},"title":{"type":"string","minLength":1,"maxLength":200,"description":"Short human-readable name for the link."},"description":{"type":"string","minLength":1,"maxLength":500,"description":"What the destination is. Shown to agents that read the link instead of following it."},"expires_at":{"type":"string","format":"date-time","pattern":"^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(?:\\.\\d+)?(?:Z|([+-](?:[01]\\d|2[0-3]):[0-5]\\d)))$","description":"ISO 8601 time after which the link stops redirecting."}},"required":["url"]},"UpdateLink":{"type":"object","properties":{"url":{"type":"string","maxLength":2048,"description":"Destination URL the short link redirects to (http or https)."},"title":{"anyOf":[{"type":"string","minLength":1,"maxLength":200,"description":"Short human-readable name for the link."},{"type":"null"}]},"description":{"anyOf":[{"type":"string","minLength":1,"maxLength":500,"description":"What the destination is. Shown to agents that read the link instead of following it."},{"type":"null"}]},"expires_at":{"anyOf":[{"type":"string","format":"date-time","pattern":"^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(?:\\.\\d+)?(?:Z|([+-](?:[01]\\d|2[0-3]):[0-5]\\d)))$","description":"ISO 8601 time after which the link stops redirecting."},{"type":"null"}]}}},"Link":{"type":"object","properties":{"id":{"type":"string","examples":["lnk_8f3k2n5q7r9t1v4x"]},"slug":{"type":"string"},"short_url":{"type":"string","format":"uri"},"url":{"type":"string","format":"uri"},"title":{"type":["string","null"]},"description":{"type":["string","null"]},"clicks":{"type":"integer"},"expires_at":{"type":["string","null"],"format":"date-time"},"created_at":{"type":"string","format":"date-time"},"updated_at":{"type":"string","format":"date-time"}}},"LinkStats":{"type":"object","properties":{"link":{"$ref":"#/components/schemas/Link"},"period":{"type":"object","properties":{"days":{"type":"integer"},"from":{"type":"string","format":"date"},"to":{"type":"string","format":"date"},"timezone":{"type":"string"}}},"total_clicks":{"type":"integer"},"visitors":{"type":"object","properties":{"human":{"type":"integer"},"ai_agent":{"type":"integer"},"bot":{"type":"integer"}}},"timeseries":{"type":"array","items":{"type":"object","properties":{"date":{"type":"string","format":"date"},"clicks":{"type":"integer"}}}},"top_referrers":{"type":"array","items":{"type":"object","properties":{"referrer":{"type":"string"},"clicks":{"type":"integer"}}}},"top_countries":{"type":"array","items":{"type":"object","properties":{"country":{"type":"string"},"clicks":{"type":"integer"}}}},"top_agents":{"type":"array","items":{"type":"object","properties":{"agent":{"type":"string"},"clicks":{"type":"integer"}}}}}},"Error":{"type":"object","properties":{"error":{"type":"object","properties":{"code":{"type":"string","enum":["invalid_request","unauthorized","not_found","slug_taken","internal_error"]},"message":{"type":"string"},"details":{"type":"array","items":{"type":"object","properties":{"field":{"type":"string"},"message":{"type":"string"}}}}}}}}}}}