HTTP API
Run your projects, ranking bots, hashtag channels and story accounts from your own code, or hand the keys to an AI agent.
503 until it ships, and the shapes below are the committed design.Overview
JSON over HTTPS. Every request is authenticated, scoped to a single account, and carries a trace id. One base URL:
https://api.tgpub.app/v1The same service layer backs the Telegram bot and the website, so all three agree on what a thing costs and who owns it. Point your own code or an AI agent at it with a scoped key.
Authentication
Every request carries an API key as a bearer token:
curl https://api.tgpub.app/v1/me \
-H "Authorization: Bearer tgp_live_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"Mint keys in the dashboard under Developer, API keys, signed in with the Telegram account that owns your bots.
A key is shown once. Only a hash is stored, so a lost key is replaced rather than recovered. Give every integration its own key: each carries its own scopes, its own rate limit and its own audit trail.
Scopes
Scopes are fixed at creation and cannot be widened. A request outside them fails 403 insufficient_scope and changes nothing.
| Scope | Grants |
|---|---|
assets:read | Bots, projects, sources, channels, story accounts, AI config |
assets:write | Settings on anything you already own |
content:read | Posts, schedule, broadcasts |
content:write | Draft, edit, approve, publish, schedule |
stats:read | Engagement, audience, rank |
billing:read | Balance, resources, renewal dates |
There is deliberately no billing:write. An API key cannot spend your balance, and that is enforced by the scope not existing rather than by a check inside a handler, so no future endpoint can inherit the ability by accident.
Errors
Errors are application/problem+json. Branch on type, which is stable; detail is written for a person and may be reworded.
HTTP/1.1 402 Payment Required
Content-Type: application/problem+json
Trace-Id: 01JF2K8QW3ZB7N4YCM6R0XDTVA
{
"type": "insufficient_balance",
"title": "Not enough balance",
"status": 402,
"detail": "This action costs $10.00 and the wallet holds $2.50."
}| type | Status | Meaning |
|---|---|---|
invalid_request | 400 | Malformed body or a failed validation |
unauthorized | 401 | Missing, revoked or expired credential |
insufficient_scope | 403 | Valid key, missing scope |
access_gate | 403 | Account suspended, banned, or onboarding unfinished |
not_found | 404 | No such resource, or it belongs to another account |
conflict | 409 | Already exists, or the state moved under you |
quota_exceeded | 409 | An account limit would be exceeded |
insufficient_balance | 402 | Costs more than the wallet holds |
rate_limited | 429 | Over the per-key budget |
upstream_failed | 502 | Telegram or an AI provider failed; safe to retry |
A resource owned by someone else returns 404, not 403, so the API never confirms which ids exist on other accounts.
Pagination
Cursor only. There is no offset parameter: these tables run to millions of rows, where offset paging both degrades and silently skips records when rows are inserted during a walk.
GET /v1/posts?limit=50
GET /v1/posts?limit=50&cursor=eyJpZCI6MTk4NDIsInRzIjoxNzk...
{ "data": [ ... ], "next_cursor": "eyJ...", "has_more": true }limit defaults to 25 and caps at 100. Walk until has_more is false and never build a cursor yourself.
Idempotency
Every POST accepts Idempotency-Key, not only the ones that touch money. Agents retry on timeouts, and a duplicate scheduled post is as unwelcome as a duplicate charge.
curl -X POST https://api.tgpub.app/v1/posts \
-H "Authorization: Bearer $TGPUB_KEY" \
-H "Idempotency-Key: 7f3c1b94-0f2e-4a1d-9c88-2b5e6a0d71f4" \
-H "Content-Type: application/json" \
-d '{"project_id":"...","body":"Hello"}'Replaying within 24 hours returns the original response with Idempotent-Replay: true. Reusing a key with a different body is 409. Use one UUID per logical action, not per retry.
Rate limits
Per key, so one noisy integration cannot starve another. Pace yourself from the headers rather than discovering the limit by hitting it.
RateLimit-Limit: 600
RateLimit-Remaining: 584
RateLimit-Reset: 41Account
/v1/meIdentity, tier, scopesany/v1/auditYour own audit trailassets:readBilling
/v1/walletBalance and tierbilling:read/v1/billing/resourcesWhat renews and whenbilling:read/v1/billing/bandwidthRelay usage this monthbilling:readAmounts are integer cents, never floats. A resource priced 0 is covered by a free allowance rather than unpriced.
Ranking bots
/v1/botsListassets:read/v1/bots/{id}One botassets:read/v1/bots/{id}Reply mode, speed, premium gateassets:write/v1/bots/{id}/statsStarts, blocks, engagementstats:read/v1/bots/{id}/audienceLanguage and premium splitstats:read/v1/bots/{id}/autobroadcastWeekly and daily settingsassets:writeReply modes
| Value | Behaviour |
|---|---|
off | The bot answers nothing |
start | A greeting on /start only |
persona | Pre-written replies at zero generation cost |
Adding or removing a bot is not on this API: a bot past the free allowance costs money, so it is a dashboard action.
Projects and sources
/v1/projectsListassets:read/v1/projects/{id}One project with its targetsassets:read/v1/projects/{id}Autopilot, publish mode, daily capassets:write/v1/projects/{id}/sourcesSourcesassets:read/v1/projects/{id}/sourcesAdd a source (free)assets:write/v1/projects/{id}/sources/{sid}Filters, skip words, rebrandassets:write/v1/projects/{id}/sources/{sid}Remove a sourceassets:writeEvery project has one main channel that cannot be removed, plus any number of extra channels. Adding an extra channel is billable and therefore a dashboard action.
Posts, schedule and broadcasts
/v1/postsThe queuecontent:read/v1/postsCreate a draftcontent:write/v1/posts/{id}Edit before publishingcontent:write/v1/posts/{id}/approveApprove, which does not publishcontent:write/v1/posts/{id}/publishPublish nowcontent:write/v1/scheduleSlotscontent:read/v1/broadcastsQueue a broadcastcontent:writeApprove and publish are separate, and approving never sends. Published posts are purged after 7 days and other terminal states after 14, so this is a working queue rather than an archive.
Other services
/v1/hashtag/channelsHashtag channelsassets:read/v1/hashtag/channels/{id}Lists and media bankassets:write/v1/story/accountsStory accountsassets:read/v1/story/accounts/{id}Slots and locationsassets:write/v1/smm/ordersSMM orders and runsassets:read/v1/ai/endpointsProviders, never key materialassets:read/v1/ai/capabilitiesModel per capabilityassets:writeSigning a story account in needs a phone code and therefore a human. AI provider keys are write-only and are never returned by any endpoint at any scope.
What the API will not do
Some actions belong to a signed-in person in the dashboard. This is a boundary, not a gap waiting to be filled.
Spending money
Topping up, adding a bot past the free allowance at $10 a month, an extra channel at $5, a hashtag channel or story account at $10. A browser session is a person who authenticated moments ago; an API key is a program, and a program can be in a loop.
Handling secrets
Submitting a bot token or an AI provider key, and signing a story account in. Those need a human and a form, not a credential sitting in an agent transcript. No endpoint returns a bot token or a provider key to anyone, under any scope.
Versioning
/v1 will not take a breaking change. Fields may be added, and clients must ignore ones they do not recognise. Anything that would break a working integration ships as /v2 with a deprecation window announced in advance. Treat an unknown enum value as one you do not handle yet, not as an error.