Developers API

Integrate SahiURL into your applications, Telegram bots, and websites.

Quick Start
Get started in 30 seconds

Your API token can be found in Dashboard → Tools.

Send a GET request with your API token and URL like this:

https://sahiurl.in/api?api=YOUR_API_KEY&url=https://example.com

You will get a JSON response like:

{"status":"success","shortenedUrl":"https://sahi.to/abc123"}

For TEXT response (just the short URL), add &format=text:

https://sahiurl.in/api?api=YOUR_API_KEY&url=https://example.com&format=text

This returns just: https://sahi.to/abc123

API Reference
Complete endpoint documentation
GET
https://sahiurl.in/api
ParameterRequiredDescription
api
Required
Your API token
url
Required
The destination URL to shorten
alias
Optional
Custom short code (2-30 chars, alphanumeric)
format
Optional
json (default) or text
POST
https://sahiurl.in/api

Headers:

x-api-key: YOUR_API_KEY
Content-Type: application/json

Body:

{
  "url": "https://example.com",
  "alias": "custom-name"
}
PHP Examples
Copy-paste code for your PHP projects

Using JSON Response:

<?php
$long_url = urlencode('https://example.com');
$api_token = 'YOUR_API_KEY';
$api_url = "https://sahiurl.in/api?api={$api_token}&url={$long_url}";

$result = @json_decode(file_get_contents($api_url), TRUE);

if ($result["status"] === 'error') {
    echo $result["message"];
} else {
    echo $result["shortenedUrl"];
}
?>

Using Plain Text Response:

<?php
$long_url = urlencode('https://example.com');
$api_token = 'YOUR_API_KEY';
$api_url = "https://sahiurl.in/api?api={$api_token}&url={$long_url}&format=text";

$result = @file_get_contents($api_url);

if ($result) {
    echo $result;
}
?>
JavaScript Examples
For Node.js and browser applications

Using Fetch:

const response = await fetch(
  'https://sahiurl.in/api?api=YOUR_API_KEY&url=' + encodeURIComponent('https://example.com')
);
const data = await response.json();
console.log(data.shortenedUrl); // https://sahi.to/abc123

Using POST with Headers:

const response = await fetch('https://sahiurl.in/api', {
  method: 'POST',
  headers: {
    'x-api-key': 'YOUR_API_KEY',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    url: 'https://example.com',
    alias: 'my-custom-link'
  })
});
const data = await response.json();
console.log(data.shortenedUrl);
Python Example
For Python scripts and bots
import requests
from urllib.parse import quote

api_key = "YOUR_API_KEY"
long_url = quote("https://example.com")

response = requests.get(f"https://sahiurl.in/api?api={api_key}&url={long_url}")
data = response.json()

if data["status"] == "success":
    print(data["shortenedUrl"])
else:
    print(data["message"])
Telegram Bot Integration
Connect SahiURL to Telegram groups

Use this format in your Telegram bot:

/shortlink sahiurl.in YOUR_API_KEY

Replace YOUR_API_KEY with your actual API key from Dashboard → Tools.

Note: Compatible with AdLinkFly-style bots. The API format matches popular URL shortener APIs.

Error Responses
Handle errors gracefully
StatusMessageDescription
400
Missing API keyAPI key not provided
400
Missing URLURL parameter missing
400
Alias already takenCustom alias is in use
401
Invalid API keyAPI key not found
500
Internal errorServer error
{"status":"error","message":"Invalid API key"}