> ## Documentation Index
> Fetch the complete documentation index at: https://docs.zerogpu.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Telegram Mini Apps

> Connect your Telegram Mini App to ZeroGPU and contribute device compute to the edge network with one script tag.

## Overview

Telegram Mini Apps run on the ZeroGPU browser SDK: one script tag in your Mini App's HTML turns the devices opening it into inference nodes on the ZeroGPU network. The SDK detects the Telegram WebApp environment automatically and adapts to it.

## Requirements

* A Telegram Mini App (a web app opened inside Telegram).
* An SDK key (`zgpu-sdk-…`) from the [Edge Operator Portal](https://edge.zerogpu.ai). When you add your app, select **Telegram Mini App** as an app type and use your `t.me` link as the website.
* The same browser requirements as the [Browser SDK](https://docs.zerogpu.ai/edge/sdk/browser.md#requirements): WebAssembly, IndexedDB, and Web Workers, all available in Telegram's in-app browser.

## Download

| Source | |
| - | - |
| **CDN** | `https://js-sdk.zerogpu.ai/dist/loader.js` (always the latest release) |
| **GitHub** | [github.com/zerogpu](https://github.com/zerogpu) |

## Installation

Add the loader to your Mini App's HTML. It always resolves the latest released SDK:

```html theme={null}
<script async src="https://js-sdk.zerogpu.ai/dist/loader.js"></script>
```

## Initialization

The simplest setup is auto-init: put your SDK key on the script tag and the SDK starts when the page loads.

```html theme={null}
<script
  async
  src="https://js-sdk.zerogpu.ai/dist/loader.js"
  edgeOperatorKey="zgpu-sdk-your-key"
></script>
```

For manual init, use `ZeroGpuSdk.initZeroGpuSdk({ edgeOperatorKey })` exactly as in the [Browser SDK](https://docs.zerogpu.ai/edge/sdk/browser.md#initialization). All the same options apply.

### App ID and app name (optional)

Pass the app ID and name from the [Edge Operator Portal](https://edge.zerogpu.ai) so the inference these devices serve is attributed to your Mini App. Copy the ID from your app's row on **My Apps**, and pass your bot username as the native ID:

```html theme={null}
<script
  async
  src="https://js-sdk.zerogpu.ai/dist/loader.js"
  edgeOperatorKey="zgpu-sdk-your-key"
  data-app-id="your-app-id"
  data-app-name="My Mini App"
  data-external-app-id="my_bot"
></script>
```

All three are optional: leaving them unset never affects registration or inference, and ZeroGPU then uses the app your SDK key belongs to.

## Authentication

The SDK authenticates with your **SDK key** (`zgpu-sdk-…`), passed as `edgeOperatorKey`. The key only joins devices to your fleet; it can't call the inference API or spend credits.

## Register device

Registration is automatic. Inside Telegram, the SDK:

* Detects that it's running inside Telegram.
* Uses the Telegram user ID as `appUserId`, so you don't need to pass it.
* Downloads and caches a model, then connects the device to ZeroGPU.

## Start contributing compute

The device contributes compute while your Mini App is open. There's nothing else to call.

## Stop / pause

Keep the handle returned by `initZeroGpuSdk` and call `shutdown()` to stop:

```js theme={null}
const zerogpu = await ZeroGpuSdk.initZeroGpuSdk({ edgeOperatorKey: 'zgpu-sdk-your-key' });

// later, e.g. when the user turns resource sharing off
await zerogpu.shutdown();
```

There is no separate pause call. Closing the Mini App also stops contribution.

## Device lifecycle

The lifecycle matches the [Browser SDK](https://docs.zerogpu.ai/edge/sdk/browser.md#device-lifecycle): `starting`, `running`, `degraded`, `shutdown`, or `error`, with `degraded`, `recovered`, and `shutdown` events.

Telegram's in-app WebViews behave differently from regular browsers, so the SDK adapts its memory and storage checks there, and includes a guard that stops it from restarting repeatedly if the WebView keeps crashing and reloading.

## Example integration

```html index.html theme={null}
<!doctype html>
<html>
  <head>
    <script src="https://telegram.org/js/telegram-web-app.js"></script>
    <script
      async
      src="https://js-sdk.zerogpu.ai/dist/loader.js"
      edgeOperatorKey="zgpu-sdk-your-key"
      enableConsoleLogs="true"
    ></script>
  </head>
  <body>
    <!-- your Mini App -->
  </body>
</html>
```

To verify, open the Mini App in Telegram Desktop or Telegram Web with developer tools, and watch the console as the SDK registers the device, loads a model, and becomes ready. Turn `enableConsoleLogs` off for release.

Once the device is online, [check that it's eligible and earning](https://docs.zerogpu.ai/edge/verify.md).

## Troubleshooting

| Symptom | Fix |
| - | - |
| Rejected at registration / `401` | The SDK key is wrong or inactive. Check it in the Edge Operator Portal. |
| SDK pinned to an old version | Load `dist/loader.js`, not `zerogpu-browser-sdk.umd.js` directly. |
| No SDK activity in the console | Add `enableConsoleLogs="true"` to the script tag. |
| `Init skipped: crash-loop guard active` | The WebView crashed repeatedly while loading the model, so the SDK is in a cooldown. It starts again once the cooldown ends. |

See [Browser troubleshooting](https://docs.zerogpu.ai/edge/sdk/browser.md#troubleshooting) for worker and CSP issues.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.