{
  "openapi": "3.1.0",
  "info": {
    "title": "TgFather Reseller API",
    "version": "2.0.0",
    "summary": "Telegram Stars, Premium, sessions, aged channels/groups/bots and Telegram Ads, in the standard SMM-panel (PerfectPanel) format.",
    "description": "One endpoint, POST https://tgfather.com/api/v2, form-encoded, with your `key` and an `action`. Full guide: https://tgfather.com/api. Test without spending using a sandbox key (action=test_key).",
    "contact": {
      "name": "TgFather",
      "url": "https://tgfather.com/api"
    }
  },
  "servers": [
    {
      "url": "https://tgfather.com"
    }
  ],
  "security": [
    {
      "formKey": []
    },
    {
      "bearer": []
    }
  ],
  "paths": {
    "/api/v2": {
      "post": {
        "operationId": "call",
        "summary": "Call an action",
        "description": "Pick the action with `action`; each action reads the parameters listed in its description. Errors answer HTTP 200 with an Error object (HTTP 429 when rate limited).",
        "requestBody": {
          "required": true,
          "content": {
            "application/x-www-form-urlencoded": {
              "schema": {
                "$ref": "#/components/schemas/Request"
              },
              "examples": {
                "services": {
                  "value": {
                    "key": "tgfather_…",
                    "action": "services"
                  }
                },
                "add": {
                  "value": {
                    "key": "tgfather_…",
                    "action": "add",
                    "service": 1,
                    "link": "@alice",
                    "quantity": 100,
                    "idempotency_key": "po-10442"
                  }
                },
                "status": {
                  "value": {
                    "key": "tgfather_…",
                    "action": "status",
                    "order": "Kp3m9x"
                  }
                },
                "statusByKey": {
                  "value": {
                    "key": "tgfather_…",
                    "action": "status",
                    "idempotency_key": "po-10442"
                  }
                },
                "orders": {
                  "value": {
                    "key": "tgfather_…",
                    "action": "orders",
                    "limit": 50,
                    "status": "in progress"
                  }
                },
                "check": {
                  "value": {
                    "key": "tgfather_…",
                    "action": "check",
                    "service": 2,
                    "link": "@alice"
                  }
                },
                "quote": {
                  "value": {
                    "key": "tgfather_…",
                    "action": "quote",
                    "service": 5,
                    "quantity": 100
                  }
                },
                "cancel": {
                  "value": {
                    "key": "tgfather_…",
                    "action": "cancel",
                    "orders": "Mx2pQ7,Hb7kW2"
                  }
                },
                "balance": {
                  "value": {
                    "key": "tgfather_…",
                    "action": "balance"
                  }
                },
                "statement": {
                  "value": {
                    "key": "tgfather_…",
                    "action": "statement",
                    "from": "2026-10-01"
                  }
                },
                "webhook": {
                  "value": {
                    "key": "tgfather_…",
                    "action": "webhook",
                    "url": "https://example.com/tgf-hook"
                  }
                },
                "testKey": {
                  "value": {
                    "key": "tgfather_…",
                    "action": "test_key"
                  }
                },
                "ticketCreate": {
                  "value": {
                    "key": "tgfather_…",
                    "action": "ticket_create",
                    "customer_ref": "tg_51234",
                    "message": "My Stars did not arrive"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The action's result, or an Error object.",
            "headers": {
              "X-Request-ID": {
                "$ref": "#/components/headers/RequestID"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "oneOf": [
                    {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Service"
                      },
                      "title": "services"
                    },
                    {
                      "$ref": "#/components/schemas/AddResult"
                    },
                    {
                      "$ref": "#/components/schemas/Order"
                    },
                    {
                      "type": "object",
                      "additionalProperties": {
                        "$ref": "#/components/schemas/Order"
                      },
                      "title": "status (orders=…)"
                    },
                    {
                      "$ref": "#/components/schemas/OrderPage"
                    },
                    {
                      "$ref": "#/components/schemas/CheckResult"
                    },
                    {
                      "$ref": "#/components/schemas/Quote"
                    },
                    {
                      "$ref": "#/components/schemas/Balance"
                    },
                    {
                      "$ref": "#/components/schemas/Statement"
                    },
                    {
                      "type": "object",
                      "title": "ticket_create / ticket_get / ticket_list",
                      "properties": {
                        "ticket": {
                          "$ref": "#/components/schemas/Ticket"
                        },
                        "thread": {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "properties": {
                              "id": {
                                "type": "integer"
                              },
                              "from": {
                                "type": "string",
                                "enum": [
                                  "customer",
                                  "support"
                                ]
                              },
                              "message": {
                                "type": "string"
                              },
                              "created_at": {
                                "type": "string",
                                "format": "date-time"
                              }
                            }
                          }
                        },
                        "tickets": {
                          "type": "array",
                          "items": {
                            "$ref": "#/components/schemas/Ticket"
                          }
                        },
                        "next": {
                          "type": "string"
                        }
                      }
                    },
                    {
                      "$ref": "#/components/schemas/Error"
                    }
                  ]
                }
              }
            }
          },
          "429": {
            "description": "Rate limited. Wait Retry-After seconds.",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                },
                "description": "Seconds to wait before retrying."
              },
              "X-Request-ID": {
                "$ref": "#/components/headers/RequestID"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    }
  },
  "webhooks": {
    "order.updated": {
      "post": {
        "summary": "An order changed state",
        "description": "Sent to the URL registered with action=webhook each time an order's `state` changes. Verify X-TGF-Signature = \"sha256=\" + hex(HMAC-SHA256(secret, X-TGF-Timestamp + \".\" + raw body)). Answer 2xx; failures retry with backoff for about 12 attempts.",
        "parameters": [
          {
            "name": "X-TGF-Timestamp",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "X-TGF-Signature",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "examples": [
                "sha256=5d1c…"
              ]
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "event",
                  "order",
                  "sent_at"
                ],
                "properties": {
                  "event": {
                    "const": "order.updated"
                  },
                  "order": {
                    "$ref": "#/components/schemas/Order"
                  },
                  "sent_at": {
                    "type": "string",
                    "format": "date-time"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Received."
          }
        }
      }
    },
    "ping": {
      "post": {
        "summary": "Test ping (action=webhook_test)",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "event",
                  "sent_at"
                ],
                "properties": {
                  "event": {
                    "const": "ping"
                  },
                  "sent_at": {
                    "type": "string",
                    "format": "date-time"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Received."
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "formKey": {
        "type": "apiKey",
        "in": "header",
        "name": "X-API-Key",
        "description": "Or send key=… in the form body. Never in the URL."
      },
      "bearer": {
        "type": "http",
        "scheme": "bearer"
      }
    },
    "headers": {
      "RequestID": {
        "schema": {
          "type": "string",
          "examples": [
            "req_9f2c4e1a7b3d5c60"
          ]
        },
        "description": "Quote it to support."
      }
    },
    "schemas": {
      "Request": {
        "type": "object",
        "required": [
          "action"
        ],
        "properties": {
          "key": {
            "type": "string",
            "description": "Live key (tgfather_…) or sandbox key (tgfather_test_…)."
          },
          "action": {
            "type": "string",
            "enum": [
              "services",
              "add",
              "status",
              "orders",
              "check",
              "quote",
              "cancel",
              "refill",
              "refill_status",
              "confirm",
              "balance",
              "statement",
              "webhook",
              "test_key",
              "keys",
              "key_create",
              "key_revoke",
              "ip_allowlist",
              "webhook_test",
              "webhook_resend",
              "webhook_log",
              "ticket_create",
              "ticket_reply",
              "ticket_list",
              "ticket_get"
            ]
          },
          "service": {
            "type": "integer",
            "description": "add, check, quote; orders filter."
          },
          "link": {
            "type": "string",
            "description": "add, check: the recipient @username or t.me link (the promoted channel for Ads)."
          },
          "quantity": {
            "type": "integer",
            "description": "add, quote."
          },
          "idempotency_key": {
            "type": "string",
            "pattern": "^[A-Za-z0-9_-]{1,64}$",
            "description": "add: your unique id for the purchase; a retry with the same key never charges twice. status: look an order up by it. Alias: client_reference."
          },
          "answer_number": {
            "type": "string",
            "description": "add, Aged only: optional owner country (ISO code, name or +dial)."
          },
          "order": {
            "type": "string",
            "description": "status, cancel, confirm: one order code."
          },
          "orders": {
            "type": "string",
            "description": "status, cancel, refill: comma-separated order codes (max 100)."
          },
          "limit": {
            "type": "integer",
            "minimum": 1,
            "maximum": 100,
            "description": "orders, statement: page size (default 50)."
          },
          "after": {
            "type": "string",
            "description": "orders, statement: the `next` cursor of the previous page."
          },
          "from": {
            "type": "string",
            "description": "orders, statement: unix time, RFC3339 or YYYY-MM-DD."
          },
          "to": {
            "type": "string",
            "description": "orders, statement: unix time, RFC3339 or YYYY-MM-DD (a bare date includes the whole day)."
          },
          "status": {
            "type": "string",
            "description": "orders: filter by status or state. ticket_list: open or closed."
          },
          "recipient": {
            "type": "string",
            "description": "orders: filter by recipient @username."
          },
          "url": {
            "type": "string",
            "description": "webhook: your public https:// URL."
          },
          "delete": {
            "type": "string",
            "enum": [
              "1"
            ],
            "description": "webhook: remove the registered URL."
          },
          "cpm": {
            "type": "number",
            "description": "add, Ads: bid per 1,000 views in USD."
          },
          "ad_title": {
            "type": "string"
          },
          "ad_text": {
            "type": "string"
          },
          "target": {
            "type": "string",
            "description": "add, Ads: comma list of channels to show the ad in."
          },
          "target_type": {
            "type": "string",
            "enum": [
              "channels",
              "users"
            ]
          },
          "name": {
            "type": "string",
            "description": "key_create: a label for the key."
          },
          "read_only": {
            "type": "string",
            "enum": [
              "1"
            ],
            "description": "key_create: make a read-only key."
          },
          "id": {
            "type": "integer",
            "description": "key_revoke: the key id."
          },
          "ips": {
            "type": "string",
            "description": "ip_allowlist: comma-separated IPs/CIDRs; must include your IP."
          },
          "clear": {
            "type": "string",
            "enum": [
              "1"
            ],
            "description": "ip_allowlist: remove the allowlist."
          },
          "message": {
            "type": "string",
            "description": "ticket_create, ticket_reply: the message (max 2000 characters)."
          },
          "subject": {
            "type": "string",
            "description": "ticket_create: optional subject (max 80)."
          },
          "customer_ref": {
            "type": "string",
            "pattern": "^[A-Za-z0-9_.:-]{1,64}$",
            "description": "ticket_create, ticket_list: your own id for the end customer; one open ticket per customer."
          },
          "ticket": {
            "type": "integer",
            "description": "ticket_reply, ticket_get: the ticket number."
          },
          "since": {
            "type": "string",
            "description": "ticket_list: only tickets updated after this time (unix, RFC3339 or YYYY-MM-DD)."
          }
        }
      },
      "Service": {
        "type": "object",
        "properties": {
          "service": {
            "type": "integer"
          },
          "name": {
            "type": "string"
          },
          "type": {
            "type": "string",
            "enum": [
              "Default",
              "Package",
              "Poll"
            ]
          },
          "category": {
            "type": "string"
          },
          "rate": {
            "type": "string",
            "description": "USD per 1,000 units; charge = quantity × rate / 1000."
          },
          "min": {
            "type": "string"
          },
          "max": {
            "type": "string",
            "description": "\"0\" while sold out."
          },
          "refill": {
            "type": "boolean"
          },
          "cancel": {
            "type": "boolean"
          },
          "dripfeed": {
            "type": "boolean"
          },
          "desc": {
            "type": "string"
          },
          "country": {
            "type": "string",
            "description": "Sessions: ISO country code."
          },
          "band": {
            "type": "string",
            "description": "Sessions: account age band (0-1m, 2-6m, 6-12m, 1-2y, 3-4y, 5y, spam, vip)."
          },
          "kind": {
            "type": "string",
            "description": "Aged: bot, group or channel."
          },
          "year": {
            "type": "integer",
            "description": "Aged: creation year."
          }
        }
      },
      "AddResult": {
        "type": "object",
        "required": [
          "order",
          "charge",
          "replayed"
        ],
        "properties": {
          "order": {
            "type": "string",
            "examples": [
              "Kp3m9x"
            ]
          },
          "charge": {
            "type": "number",
            "description": "USD debited."
          },
          "replayed": {
            "type": "boolean",
            "description": "true = this matched an earlier add by idempotency_key; nothing new was charged."
          },
          "idempotency_key": {
            "type": "string"
          }
        }
      },
      "Order": {
        "type": "object",
        "properties": {
          "order": {
            "type": "string"
          },
          "service": {
            "type": "integer"
          },
          "link": {
            "type": "string"
          },
          "quantity": {
            "type": "integer"
          },
          "charge": {
            "type": "string"
          },
          "start_count": {
            "type": "string"
          },
          "remains": {
            "type": "string",
            "description": "Units not delivered (refunded on Canceled/Partial)."
          },
          "currency": {
            "type": "string"
          },
          "status": {
            "type": "string",
            "enum": [
              "In progress",
              "Completed",
              "Partial",
              "Canceled"
            ]
          },
          "state": {
            "type": "string",
            "description": "Machine-readable state, see https://tgfather.com/api#statuses."
          },
          "next_action": {
            "type": "string",
            "enum": [
              "wait",
              "recipient_join_invite",
              "recipient_start_bot",
              "contact_support",
              "none"
            ]
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "idempotency_key": {
            "type": "string"
          },
          "refunded": {
            "type": "string"
          },
          "error_code": {
            "type": "string"
          },
          "error_message": {
            "type": "string"
          },
          "sandbox": {
            "type": "boolean"
          },
          "result": {
            "type": "object",
            "description": "Product detail: download links (sessions), invite/transfer (aged), budget/spent/views/clicks (ads)."
          }
        }
      },
      "OrderPage": {
        "type": "object",
        "properties": {
          "orders": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Order"
            }
          },
          "next": {
            "type": "string"
          }
        }
      },
      "CheckResult": {
        "type": "object",
        "properties": {
          "service": {
            "type": "integer"
          },
          "link": {
            "type": "string"
          },
          "valid": {
            "type": "boolean"
          },
          "verified": {
            "type": "boolean"
          },
          "recipient_type": {
            "type": "string",
            "enum": [
              "user",
              "bot",
              "chat",
              "not_found",
              "unknown",
              "invalid",
              "not_required"
            ]
          },
          "error_code": {
            "type": "string"
          },
          "error": {
            "type": "string"
          }
        }
      },
      "Quote": {
        "type": "object",
        "properties": {
          "service": {
            "type": "integer"
          },
          "quantity": {
            "type": "integer"
          },
          "charge": {
            "type": "number"
          },
          "currency": {
            "type": "string"
          },
          "available": {
            "type": "boolean"
          },
          "quoted_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "Balance": {
        "type": "object",
        "properties": {
          "balance": {
            "type": "string"
          },
          "currency": {
            "type": "string"
          }
        }
      },
      "Statement": {
        "type": "object",
        "properties": {
          "entries": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "type": {
                  "type": "string",
                  "enum": [
                    "deposit",
                    "charge",
                    "refund",
                    "adjustment"
                  ]
                },
                "amount": {
                  "type": "string"
                },
                "balance_after": {
                  "type": "string"
                },
                "product": {
                  "type": "string"
                },
                "order": {
                  "type": "string"
                },
                "created_at": {
                  "type": "string",
                  "format": "date-time"
                }
              }
            }
          },
          "currency": {
            "type": "string"
          },
          "next": {
            "type": "string"
          }
        }
      },
      "Error": {
        "type": "object",
        "required": [
          "error"
        ],
        "properties": {
          "error": {
            "type": "string"
          },
          "error_code": {
            "type": "string",
            "description": "See https://tgfather.com/api#errors."
          },
          "request_id": {
            "type": "string"
          },
          "charged": {
            "type": "boolean",
            "description": "add only: whether money was taken."
          },
          "retryable": {
            "type": "boolean",
            "description": "add only: whether the same request may succeed later."
          }
        }
      },
      "Ticket": {
        "type": "object",
        "properties": {
          "ticket": {
            "type": "integer"
          },
          "customer_ref": {
            "type": "string"
          },
          "subject": {
            "type": "string"
          },
          "message": {
            "type": "string"
          },
          "status": {
            "type": "string",
            "enum": [
              "open",
              "closed"
            ]
          },
          "last_sender": {
            "type": "string",
            "enum": [
              "customer",
              "support"
            ]
          },
          "replies": {
            "type": "integer"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      }
    }
  }
}
