The txt.lk API lets you create and expand shortened URLs from your own software. txt.lk is a simple, privacy-friendly URL shortener.
To use the txt.lk API, you must first obtain an API key. Send a request to rikard@textalk.se
Once you receive your API key, keep it secure as it is used to authenticate all requests.
All API requests require the Authorization header containing your API key. Without a valid API key, the API will return an error.
Authorization: <your_api_key>
POST https://txt.lk/api/index.php?endpoint=shorten
Creates a shortened URL for a given original URL. Automatically generates QR codes for the shortened URL and stores them in hierarchical directories based on the first three characters of the short key.
| Key | Value |
|---|---|
| Authorization | Your API key |
| Content-Type | application/json |
{
"url": "https://www.youtube.com/watch?v=WDiB4rtp1qw"
}
On success:
{
"success": true,
"short_url": "https://txt.lk/DIG30",
"qr_codes": {
"pngUrl": "https://txt.lk/qr/D/I/G/DIG30.png",
"svgUrl": "https://txt.lk/qr/D/I/G/DIG30.svg"
}
}
On failure (e.g., missing or invalid URL):
{
"success": false,
"error": "Invalid URL."
}
GET https://txt.lk/api/index.php?endpoint=expand&key=<short_key>
Retrieves the original URL for a given shortened URL key.
| Key | Value |
|---|---|
| Authorization | Your API key |
| Parameter | Description |
|---|---|
| key | The shortened URL key (e.g., DIG30) |
On success:
{
"success": true,
"original_url": "https://www.youtube.com/watch?v=WDiB4rtp1qw"
}
On failure (e.g., key not found):
{
"success": false,
"error": "Short key not found."
}
GET https://txt.lk/api/index.php?endpoint=usaged&key=<short_key>
Retrieves the usage count (number of times accessed) for a given shortened URL key.
| Key | Value |
|---|---|
| Authorization | Your API key |
| Parameter | Description |
|---|---|
| key | The shortened URL key (e.g., DIG30) |
On success:
{
"success": true,
"usage_count": 42
}
On failure (e.g., key not found):
{
"success": false,
"error": "Short key not found."
}
All shortened URLs automatically receive corresponding QR codes in PNG and SVG formats. These QR codes are stored in hierarchical directories based on the first three characters of the shortened key to optimize file organization and scalability.
The QR codes are generated at the following URLs:
https://txt.lk/qr/<first_char>/<second_char>/<third_char>/<short_key>.pnghttps://txt.lk/qr/<first_char>/<second_char>/<third_char>/<short_key>.svgReplace <first_char>, <second_char>, and <third_char> with the corresponding characters from the shortened URL key.
For the shortened URL key DIG30:
Every response is JSON. A failed request has "success": false and an "error" message.
| HTTP status | Message | Description |
|---|---|---|
| 401 | Invalid or missing API key. | The request did not include a valid API key. |
| 200 | Invalid URL. | The provided URL is not valid. |
| 200 | Short key not found. | The specified shortened URL key does not exist. |
| 200 | Links to this destination are not allowed. | The destination host is on the block list (phishing, suspect sites and other link shorteners). |
| 200 | This link has been disabled. | Returned by expand when the destination is blocked. |
| 429 | Too many links were made with this key. Try again later. | The key made too many links in one hour. The Retry-After header shows the wait in seconds. |
| 200 | Invalid endpoint or method. | The endpoint name or the HTTP method is not supported. |
Always check the success field. Only authentication errors use a non-200 HTTP status.
https://txt.lk to ensure secure communication.If you encounter any issues or have questions, please contact Textalk Support: