How to generate short links and QR codes from Python
Use Python to call the 1get API, create short links, and receive QR metadata in the same response for jobs, scripts, internal tools, and automation services.
POST /api/v1/links/shorten
requests or httpx
Internal tools, queue jobs, reporting scripts, backend services
GET /api/v1/usage for current billing window
Python is a strong fit for background jobs, admin tooling, and automation services that need reliable short-link creation without browser sessions. The 1get external API is designed for exactly that machine-to-machine path.
The first production pattern is simple: create a scoped key in the dashboard, store it in your secret manager, call the shorten endpoint, and consume the returned short URL plus QR metadata in one response.
Keep the key server-side and treat the request as a machine workflow
The Python caller should never need to choose an organization or send browser cookies. A scoped API key already resolves organization ownership, allowed scopes, and plan entitlements.
- Prefer Authorization: Bearer <api_key>.
- Use a fresh Idempotency-Key for each new write attempt.
- Handle non-2xx responses as structured contract failures, not generic transport errors.
Send one request and use the QR metadata immediately
For most backend tasks, the shorten response gives you everything you need: the short URL, link id, and QR code object for later download or display.
- A successful shorten-plus-QR flow counts as one API call.
- If the same idempotency key is reused with a different payload, the API returns a conflict instead of silently creating a second record.
This pattern works well in cron jobs, Celery workers, FastAPI services, and internal tooling.
import os
import uuid
import requests
payload = {
"original_url": "https://acme.ai/reports/q2-launch",
"custom_slug": "q2-launch",
"qr": {"include": True, "format": "PNG", "size": 256},
}
response = requests.post(
"https://1get.site/api/v1/links/shorten",
headers={
"Authorization": f"Bearer {os.environ['ONEGET_API_KEY']}",
"Content-Type": "application/json",
"Idempotency-Key": str(uuid.uuid4()),
},
json=payload,
timeout=15,
)
response.raise_for_status()
data = response.json()["data"]
print(data["short_url"])
print(data["qr_code"]["url"])Need the exact request and quota contracts?
Use the public docs for field-level API detail, pricing for plan depth, and the comparison page when migration or vendor fit is part of the buying discussion.
Move from the Python pattern into the full auth, scope, and endpoint reference.
See the exact response shape for quota, reset date, and active key counts.
Choose the right plan before Python jobs become a larger operational lane.
Use the comparison page when the Python integration decision is still framed around Bitly.
Pair the write lane with usage visibility and sane retry rules
Python jobs often run in batches or retry automatically. Make the API contract part of that operating model instead of treating it like a fire-and-forget request.
Read GET /api/v1/usage when your worker needs to understand the current window, remaining allowance, or active key count. That gives operations teams a cleaner view than guessing from task failures later.
- Retry only when you have a transport failure or clear retryable status.
- Use idempotency keys whenever the same task can be replayed.
- Move to Business when multiple services or larger batch patterns share the same API lane.
Keep the intent cluster connected.
These follow-up guides cover adjacent implementation paths so searchers and evaluators can move deeper without losing context.
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.
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.