HTTP API

Run your projects, ranking bots, hashtag channels and story accounts from your own code, or hand the keys to an AI agent.

Partly live. Account, wallet, bots and projects answer now. Everything else returns 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/v1

The 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.

ScopeGrants
assets:readBots, projects, sources, channels, story accounts, AI config
assets:writeSettings on anything you already own
content:readPosts, schedule, broadcasts
content:writeDraft, edit, approve, publish, schedule
stats:readEngagement, audience, rank
billing:readBalance, 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."
}
typeStatusMeaning
invalid_request400Malformed body or a failed validation
unauthorized401Missing, revoked or expired credential
insufficient_scope403Valid key, missing scope
access_gate403Account suspended, banned, or onboarding unfinished
not_found404No such resource, or it belongs to another account
conflict409Already exists, or the state moved under you
quota_exceeded409An account limit would be exceeded
insufficient_balance402Costs more than the wallet holds
rate_limited429Over the per-key budget
upstream_failed502Telegram 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:     41

Account

GET/v1/meIdentity, tier, scopesany
GET/v1/auditYour own audit trailassets:read

Billing

GET/v1/walletBalance and tierbilling:read
GET/v1/billing/resourcesWhat renews and whenbilling:read
GET/v1/billing/bandwidthRelay usage this monthbilling:read

Amounts are integer cents, never floats. A resource priced 0 is covered by a free allowance rather than unpriced.


Ranking bots

GET/v1/botsListassets:read
GET/v1/bots/{id}One botassets:read
PATCH/v1/bots/{id}Reply mode, speed, premium gateassets:write
GET/v1/bots/{id}/statsStarts, blocks, engagementstats:read
GET/v1/bots/{id}/audienceLanguage and premium splitstats:read
PUT/v1/bots/{id}/autobroadcastWeekly and daily settingsassets:write

Reply modes

ValueBehaviour
offThe bot answers nothing
startA greeting on /start only
personaPre-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

GET/v1/projectsListassets:read
GET/v1/projects/{id}One project with its targetsassets:read
PATCH/v1/projects/{id}Autopilot, publish mode, daily capassets:write
GET/v1/projects/{id}/sourcesSourcesassets:read
POST/v1/projects/{id}/sourcesAdd a source (free)assets:write
PATCH/v1/projects/{id}/sources/{sid}Filters, skip words, rebrandassets:write
DELETE/v1/projects/{id}/sources/{sid}Remove a sourceassets:write

Every 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

GET/v1/postsThe queuecontent:read
POST/v1/postsCreate a draftcontent:write
PATCH/v1/posts/{id}Edit before publishingcontent:write
POST/v1/posts/{id}/approveApprove, which does not publishcontent:write
POST/v1/posts/{id}/publishPublish nowcontent:write
GET/v1/scheduleSlotscontent:read
POST/v1/broadcastsQueue a broadcastcontent:write

Approve 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

GET/v1/hashtag/channelsHashtag channelsassets:read
PATCH/v1/hashtag/channels/{id}Lists and media bankassets:write
GET/v1/story/accountsStory accountsassets:read
PATCH/v1/story/accounts/{id}Slots and locationsassets:write
GET/v1/smm/ordersSMM orders and runsassets:read
GET/v1/ai/endpointsProviders, never key materialassets:read
PATCH/v1/ai/capabilitiesModel per capabilityassets:write

Signing 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.