Overview
Each character of each code is picked independently with Node's `crypto.randomInt`, a cryptographically secure source, from the set named by `charset`. The sets are fixed: `alphanumeric` (the default) uses A-Z, a-z and 0-9, 62 characters; `alpha` uses A-Z and a-z, 52; `numeric` uses 0-9; `hex` uses 0-9 and lowercase a-f; and `base58` uses 58 characters that omit 0, O, uppercase I and lowercase l, so codes can be read aloud or typed from print with fewer mistakes. `charset` is case-insensitive.
`length` sets characters per code, from 4 to 32 with a default of 8. `count` sets how many codes are returned, from 1 to 100 with a default of 1.
The number of possible codes is the size of the set raised to the power of the length. An 8-character alphanumeric code has 62^8 possibilities while a 6-digit numeric code has only 10^6, so choose the set and length with the size of your campaign in mind. Codes within a batch are not deduplicated against each other or against earlier requests; collisions are unlikely at reasonable lengths but possible, especially with short numeric codes, so check new codes against the ones you have already issued.
The response echoes `length`, `charset` and `count`, the actual number of entries in `codes`. `url_safe` is true for all five sets, because none of them contains a character that needs escaping in a URL path or query string.
Live Test Short Code Generator API →
Endpoint
One host, one path per API. The block below shows this call in four languages; every one of them is the same HTTP request. Making requests covers the timeouts, retries and parameter rules that apply to all of them. The SDKs wrap the same call in a typed client.
curl "https://api.apiverve.com/v1/shortcodegenerator?count=5&length=8&charset=alphanumeric" \
-H "x-api-key: your_api_key_here"const res = await fetch('https://api.apiverve.com/v1/shortcodegenerator?count=5&length=8&charset=alphanumeric', {
headers: { 'x-api-key': 'your_api_key_here' },
});
if (!res.ok) throw new Error(`${res.status} ${await res.text()}`);
const { data } = await res.json();
console.log(data);import requests
res = requests.get(
"https://api.apiverve.com/v1/shortcodegenerator?count=5&length=8&charset=alphanumeric",
headers={"x-api-key": "your_api_key_here"},
timeout=15,
)
res.raise_for_status()
print(res.json()["data"])package main
import (
"fmt"
"io"
"net/http"
)
func main() {
req, _ := http.NewRequest("GET", "https://api.apiverve.com/v1/shortcodegenerator?count=5&length=8&charset=alphanumeric", nil)
req.Header.Set("x-api-key", "your_api_key_here")
res, err := http.DefaultClient.Do(req)
if err != nil {
panic(err)
}
defer res.Body.Close()
out, _ := io.ReadAll(res.Body)
fmt.Println(string(out))
}Replace your_api_key_here with the key from your dashboard. When the inputs arrive as a list rather than one at a time, batch requests run up to 200 of them through this same API in a single call.
Authentication
Send your key in the x-api-key header. That is the only auth step — there is no token exchange and no per-endpoint scope to configure. Authentication covers creating, rotating and revoking keys.
A 401 means the key is missing, invalid or expired. A 403 means the key is valid but not permitted here — blocked by a key restriction or an IP allow-list. Running out of credits is a 429.
Parameters
Sent in the query string. Premium parameters are accepted on every plan but only take effect on plans that include them.
| Parameter | Type | Description |
|---|---|---|
countOptional | integer | Number of codes to generate default 1 · range 1–100 |
lengthOptional | integer | Length of each code default 8 · range 4–32 |
charsetOptional | string | Character setalphanumericalphanumerichexbase58default alphanumeric |
Response
Every API returns the same three top-level keys, so one response handler covers your whole integration: status, error and data. Only data changes shape. Response format covers the envelope, the other output formats and how premium fields are withheld.
{
"status": "ok",
"error": null,
"data": {
"codes": [
"bgiFznFh",
"jr84hHsG",
"Q77qABwn",
"gvMjXxXs",
"WDPJzCsi"
],
"count": 5,
"length": 8,
"charset": "alphanumeric",
"url_safe": true
}
}
Response fields
Paths are relative to data. Premium fields are absent rather than zeroed on plans that do not include them, so check for presence instead of comparing to 0.
| Field | Type | Example | Description |
|---|---|---|---|
codes | array | [bgiFznFh, ...] | Array of generated short codes |
count | number | 5 | Number of codes generated |
length | number | 8 | Length of each generated code |
charset | string | "alphanumeric" | Character set used for generation |
url_safe | boolean | true | Whether the generated codes are safe to use in a URL without encoding |
Errors
Read the HTTP status first, then error for the specific reason. The body names the parameter that has to change. Error handling covers the full status list and which of them are worth retrying.
| Status | Meaning | What to do |
|---|---|---|
400 | Input was rejected | Read error; it names the parameter. |
401 | Key missing or invalid | Check the header name and the key value. |
403 | Key valid, but not permitted | A key restriction or IP allow-list; see key scoping. |
429 | Rate limited, or out of credits | Read error to tell them apart; see rate limits. |
Use cases
- URL Shortening
- Generate short codes for URL shortening services and link tracking
- Voucher Systems
- Create unique voucher and coupon codes for e-commerce and promotions
- Temporary Access
- Generate temporary access codes and one-time passwords for authentication
- Referral Programs
- Create short referral codes for marketing and referral tracking systems
Other ways to use Short Code Generator
Set up Short Code Generator on APIVerve, or reach the same source a different way. Your APIVerve account and credits work on all of them — one key, one balance.
Related
More in Data Generation: