# TronGasAi — technical documentation

> Rent TRON energy and bandwidth programmatically. This single file contains every page of the
> technical documentation. Machine-readable API contract (OpenAPI 3.1):
> https://docs.trongas.ai/openapi/trongas.json

## Contents

1. API overview — https://docs.trongas.ai/developers/overview/
2. Authentication — https://docs.trongas.ai/developers/authentication/
3. Errors — https://docs.trongas.ai/developers/errors/
4. Webhooks reference — https://docs.trongas.ai/developers/webhooks/
5. MCP server — https://docs.trongas.ai/ai-agents/mcp/
6. llms.txt — https://docs.trongas.ai/ai-agents/llms/

---
## API overview

Source: https://docs.trongas.ai/developers/overview/

> Base URL, versioning and conventions for the TronGasAi API.

The TronGasAi API is a versioned REST API. Authenticate with an API key and drive the same actions available
in the dashboard: pricing, balance, orders, automations and webhooks.

## Base URL

```
https://trongas.ai/api/v1
```

## Conventions

- **Auth** — send your key as the `X-Api-Key` header. See [Authentication](/developers/authentication/).
- **Money** — amounts are strings in **TRX** (e.g. `"5.502"`), never floats.
- **Errors** — RFC 7807 `application/problem+json` with a machine-readable `code`. See [Errors](/developers/errors/).
- **Idempotency** — money-moving requests (creating an order) take an `Idempotency-Key` header; retrying with
  the same key returns the original result instead of charging twice.

## Endpoints

Every endpoint is documented under **[Endpoints](/developers/api/)** in the sidebar, grouped by area:

- **[Pricing](/developers/api/operations/pricing-get/)** and **[Rate](/developers/api/operations/rate-get/)** —
  public, no key required.
- **[Wallet](/developers/api/operations/wallet-balance/)** — balance, deposit address, ledger history.
- **[Orders](/developers/api/operations/orders-create/)** — preview and buy energy or bandwidth.
- **[Automations](/developers/api/operations/automations-create/)** — auto-refill, auto-renewal and smart rules.
- **[Webhooks](/developers/api/operations/webhooks-create/)** — register endpoints and inspect deliveries.
- **[Notifications](/developers/api/operations/notifications-list/)** — in-app events for your account.

Those pages are generated from our OpenAPI description, which is produced by the API's own build — so they
describe the API that is actually deployed, not a copy of it that someone remembered to update. The
description itself is available if you want to generate a client:

```
https://docs.trongas.ai/openapi/trongas.json
```

## Getting a key

Issue a key in the dashboard under **Settings → API keys**. Pick the narrowest scope that does the job and set
a daily spend limit — especially if an AI agent will hold the key. See
[Authentication](/developers/authentication/).

---

## Authentication

Source: https://docs.trongas.ai/developers/authentication/

> API keys, scopes and daily spend limits.

Authenticate every request with an API key in the `X-Api-Key` header:

```http
GET /api/v1/wallet/balance HTTP/1.1
Host: trongas.ai
X-Api-Key: tgk_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
```

Create and manage keys in the dashboard (**Settings → API keys**). The raw key is shown **once** at creation —
store it securely. Creating a key requires at least **100 TRX** on your balance. You can hold multiple keys and rotate them (issue a new one, revoke the old).

## Scopes

Each key has an access level. Higher levels include everything below them (`full` ⊇ `purchase` ⊇ `read`).

| Scope | Can do | Cannot do |
|---|---|---|
| `read` | Read prices, balance, orders, automations, deliveries | Spend or change anything |
| `purchase` | `read` + place orders, create/manage automations (spends TRX) | Manage account config (webhooks) |
| `full` | `purchase` + manage webhooks and other config | — |

Calling an endpoint above your key's scope returns **403** with code `api_key.insufficient_scope`. A read-only
key is a safe way to let an agent watch an account without any spending power.

## Daily spend limit

A key can carry an optional **daily spend limit** in TRX (calendar day, UTC). When set, order charges initiated
by the key — plus per-delivery charges from automations that key created — count toward the day's total. A
request that would exceed the limit is rejected with **403** `api_key.spend_limit_exceeded`.

Set the scope and limit when you create the key; the limit is editable later. Operators can also view and
adjust limits.

## Two ways to authenticate

- **API key** (`X-Api-Key`) — for machines and AI agents; subject to scope and spend limits.
- **Session cookie** (JWT) — the dashboard's own auth for humans; not used for programmatic access.

---

## Errors

Source: https://docs.trongas.ai/developers/errors/

> Error format and machine-readable codes.

Errors use RFC 7807 `application/problem+json` with an extra machine-readable **`code`**:

```json
{
  "status": 403,
  "title": "This API key lacks the required 'purchase' scope.",
  "code": "api_key.insufficient_scope"
}
```

Always branch on `code`, not on the human-readable `title`.

## Common codes

| HTTP | `code` | Meaning |
|---|---|---|
| 400 | `order.invalid` | Invalid order/automation parameters (volume, duration, address) |
| 400 | `validation_failed` | Request failed validation; per-field messages are in `errors` |
| 401 | `unauthorized` | Missing, invalid or revoked key (`WWW-Authenticate: ApiKey …`) |
| 402 | `wallet.insufficient_balance` | Not enough TRX on balance |
| 403 | `api_key.insufficient_scope` | Key's scope is below what the endpoint requires |
| 403 | `api_key.spend_limit_exceeded` | Would exceed the key's daily spend limit |
| 429 | `rate_limited` | Too many requests |
| 502 | `provider.upstream_error` | Energy provider temporarily unavailable (any charge is refunded). On automation pause / resume / cancel the rule keeps its previous status — retry, it's safe |
| 503 | `pricing.unavailable` | The price is temporarily unknown. Nothing was charged and nothing was created — retry after the `Retry-After` header; for orders, reuse the same `Idempotency-Key`. We never quote or charge a zero price instead |

Validation errors (bad request bodies) carry `code: "validation_failed"` and an `errors` object keyed by field:

```json
{
  "status": 400,
  "title": "One or more validation errors occurred.",
  "code": "validation_failed",
  "errors": { "volume": ["The value 'abc' is not valid."] }
}
```

Business errors carry a domain `code` and a human-readable `title`/`detail` instead of `errors`.

---

## Webhooks reference

Source: https://docs.trongas.ai/developers/webhooks/

> Payload format, signature and verification for outbound webhooks.

We POST a JSON envelope to your endpoint for each event. Manage endpoints via the dashboard or the
`/webhooks` API (needs a `full`-scope key).

## Events

- `order.filled` — an order was delivered
- `order.failed` — an order failed and was refunded
- `deposit.credited` — a deposit was credited to your balance
- `automation.paused` — a rule paused (balance too low)
- `automation.resumed` — a rule auto-resumed after top-up

## Set one up

1. Add an endpoint (HTTPS URL) in **Webhooks** in the dashboard and choose which events to receive.
2. Copy the **signing secret** shown once — you'll use it to verify deliveries.
3. Send a **test ping** to check your endpoint receives events.

## Payload

```json
{
  "id": "8f0c…",
  "type": "order.filled",
  "createdAt": "2026-07-16T12:00:00Z",
  "data": { "orderId": "…", "status": "Filled", "resource": "energy", "volume": 131000, "totalTrx": "5.502" }
}
```

## Headers

| Header | Value |
|---|---|
| `X-TronGas-Event` | event type, e.g. `order.filled` |
| `X-TronGas-Delivery` | delivery id (use it to de-duplicate) |
| `X-TronGas-Timestamp` | Unix seconds (part of the signature) |
| `X-TronGas-Signature` | `sha256=<hex HMAC>` |

## Verify the signature

The signature is `HMAC-SHA256(secret, "{timestamp}.{rawBody}")`, hex-encoded. Recompute it from the **raw**
request body and compare in constant time. Optionally reject old timestamps to prevent replay.

```js
import crypto from "node:crypto";

function verify(rawBody, headers, secret) {
  const ts = headers["x-trongas-timestamp"];
  const sig = headers["x-trongas-signature"]; // "sha256=<hex>"
  const expected =
    "sha256=" + crypto.createHmac("sha256", secret).update(`${ts}.${rawBody}`).digest("hex");
  const a = Buffer.from(sig ?? "");
  const b = Buffer.from(expected);
  // timingSafeEqual throws on different lengths, so compare lengths first.
  return a.length === b.length && crypto.timingSafeEqual(a, b);
}
```

## Delivery & retries

We expect a `2xx` response. Non-2xx or timeout triggers retries with exponential backoff (about 30s → 6h, up
to 6 attempts) before the delivery is marked failed. See the delivery log per endpoint in the dashboard.

---

## MCP server

Source: https://docs.trongas.ai/ai-agents/mcp/

> Drive TronGasAi from an AI assistant with scoped, spend-limited keys.

TronGasAi ships an **MCP server** — a thin wrapper over the API that exposes actions as tools an AI assistant
(e.g. Claude Desktop) can call. It authenticates with an **API key**, so everything is bounded by that key's
[scope and daily spend limit](/developers/authentication/).

## Tools

- **Start here** — `whoami` (checks the key, shows its scope and daily limit), `get_balance`,
  `get_deposit_address` (where to top up), `get_order_options` / `get_automation_options` (current limits and durations).
- **Read** — `get_pricing`, `preview_order`, `preview_refill_cost`, `list_orders`, `get_order`, `list_automations`
  (work with any key).
- **Write (spends TRX)** — `buy_energy`, `create_auto_refill`, `create_auto_renewal`, `enable_smart`,
  `pause_automation` / `resume_automation` / `cancel_automation` (need a `purchase` or `full` key).

Each write tool is labelled with the scope it needs. A **read-only** key lets an agent monitor an account with
no ability to spend; add a **daily spend limit** to cap a `purchase` key. `buy_energy` takes an optional
`idempotencyKey`: pass the same value when retrying a purchase and you get the original order, not a second
charge. Orders settle asynchronously — after `buy_energy`, poll `get_order` until the status is `Filled`.

The server also sends the agent a short set of instructions on connect (check the key, check the balance,
preview before spending), so a fresh agent follows the safe order without being told.

## Recommended setup for agents

1. Create a dedicated API key in the [dashboard](https://trongas.ai/dashboard/api-keys) with the **least** scope the
   agent needs (`read` is the default; choose `purchase` to let it act).
2. Set a **daily spend limit** appropriate to the task.
3. Connect your MCP client to the remote server below using that key. Rotate or revoke it anytime from the dashboard.

The dashboard shows a ready-made prompt, MCP config and Claude Code command right after you create a key.

## Connect

Remote MCP server (Streamable HTTP, nothing to install):

```
https://mcp.trongas.ai/mcp
```

Authenticate with a request header — either `Authorization: Bearer <your-api-key>` or `X-Api-Key: <your-api-key>`.
The server is stateless: it doesn't store your key, it reads it fresh from the header on every call. A wrong or
revoked key is rejected with `401` when the client connects.

Examples:

```
# Claude Code
claude mcp add --transport http trongasai https://mcp.trongas.ai/mcp --header "X-Api-Key: tgk_..."
```

```json
{
  "mcpServers": {
    "trongasai": {
      "url": "https://mcp.trongas.ai/mcp",
      "headers": { "X-Api-Key": "tgk_..." }
    }
  }
}
```

This is header-based auth, not an OAuth "connect" flow — your MCP client needs to support sending a custom
header, not just a one-click account link. If it can't, use the [REST API](/developers/overview/) directly.

---

## llms.txt

Source: https://docs.trongas.ai/ai-agents/llms/

> A machine-readable index of these docs for LLMs and agents.

We publish an [`llms.txt`](https://llmstxt.org/) file — a concise, machine-readable index of this
documentation that LLMs and agents can fetch to find the right pages.

- **Location:** `https://trongas.ai/llms.txt` (served at the site root, per the spec).
- **Contents:** links to the dashboard guides (on trongas.ai), API reference and AI-agent pages, with one-line descriptions.

For programmatic integration, prefer the [API reference](/developers/overview/) and the
[MCP server](/ai-agents/mcp/). The full machine-readable **OpenAPI** description is at
[/openapi/trongas.json](https://docs.trongas.ai/openapi/trongas.json); all pages in one file are at
[/docs.md](https://docs.trongas.ai/docs.md).
