How to add a link shortener API to a Next.js app
Use 1get from a Next.js application to create branded short links, return QR metadata in the same response, and keep retries safe with idempotency.
POST /api/v1/links/shorten
Authorization: Bearer <api_key>
Basic for first production use, Business for heavier volume
App backends, invite flows, transactional messaging, customer-share surfaces
If your Next.js product needs short links, QR assets, or programmatic redirect control, treat it as link infrastructure rather than a dashboard shortcut. That means server-side auth, stable request contracts, and a clear plan for retries, usage, and ownership.
1get is built for that model. Human admins use the dashboard to create scoped keys. Your app uses the external API to create links, retrieve metadata, and keep automation activity tied to the subscribed organization.
Use a link API instead of a private slug table
A custom slug table looks simple until you need QR support, auditing, rate controls, and machine access patterns that work across products, jobs, and internal tools.
- The same API surface can support app backends, queue workers, and AI flows.
- Short URL creation and QR metadata come back in the same response.
- Usage limits and key scopes stay outside your application business logic.
Keep shortening on the server side. Do not hand public browser clients raw API keys or tenant authority.
Create one server-side helper around the shorten endpoint
A small helper in your Next.js server layer is enough for the first integration. It can inject the API key, create an idempotency key for retries, and return a stable contract to the rest of your app.
Keep the helper inside a route handler, server action, or application service. That way the API key stays in server-side environment variables and the rest of the app consumes a simple function.
- Use an Idempotency-Key when the caller might retry.
- Store the returned link id if your app will read link or QR metadata later.
- Let the rest of the product work with short_url and qr_code.url instead of the raw external response.
Use a direct cURL request first when you want to verify auth, idempotency, and the QR response before wiring the app helper.
curl -X POST https://1get.site/api/v1/links/shorten \
-H "Authorization: Bearer 1g_live_xxxxx" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: 7c8ff59c-17aa-4178-8890-b71af19f5261" \
-d '{
"original_url": "https://acme.ai/workflows/agent-invite/42",
"custom_slug": "agent-launch",
"qr": { "include": true, "format": "SVG", "size": 256 }
}'A small server-only helper is enough for the first production lane.
import 'server-only';
type ShortenPayload = {
original_url: string;
custom_slug?: string;
qr?: { include?: boolean; format?: 'PNG' | 'SVG'; size?: number };
};
export async function createShortLink(payload: ShortenPayload) {
const response = await fetch('https://1get.site/api/v1/links/shorten', {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.ONEGET_API_KEY}`,
'Content-Type': 'application/json',
'Idempotency-Key': crypto.randomUUID(),
},
body: JSON.stringify(payload),
cache: 'no-store',
});
if (!response.ok) {
throw new Error(`1get shorten failed: ${response.status}`);
}
const body = await response.json();
return body.data;
}Turn the implementation outline into the exact request contract
Move from the guide into the live endpoint docs, plan ladder, and Bitly comparison surface when you need details or buying support.
Start from the public docs quickstart before drilling into individual endpoint pages.
See auth headers, request fields, idempotency behavior, and example responses.
Match keys, monthly calls, and rate limits to the integration you are building.
Use the comparison page when the technical decision is still framed around Bitly.
Render the returned contract and keep the integration operationally clean
The MVP route is designed so a single response is enough for most product surfaces: the short URL is ready for the UI and the QR object can feed a download button, share flow, or customer-facing asset.
As volume grows, pair the shorten helper with GET /api/v1/usage so your app or admin tooling can see the current billing window, active key count, and usage limit before traffic surprises the team.
- Basic is usually enough for the first production flow.
- Business is the more natural plan once multiple environments, teams, or read-heavy integrations appear.
- Do not build tenant selection into your client payloads. Organization context comes from the API key.
Keep the intent cluster connected.
These follow-up guides cover adjacent implementation paths so searchers and evaluators can move deeper without losing context.
Create branded short links for workflow tools, scheduled jobs, partner automations, and internal operations without relying on dashboard sessions or manual copy-paste.
Give AI agents a stable short-link tool with scoped keys, idempotent writes, auditable mutations, and a contract that works inside products, jobs, and automation runners.
Move from Bitly into 1get by remapping core shorten flows, QR behavior, API-key auth, and operational visibility without turning the migration into a feature-for-feature clone project.