# Telegram API tokens: find, store, rotate, and use them safely with AI agents

Source: https://botpassword.com/keys/telegram
Last checked: 2026-10-25

Telegram Bot API tokens are issued by @BotFather when you create a bot with /newbot. A token has two parts, a numeric bot ID and a secret string, separated by a colon, and is used in the request URL as `https://api.telegram.org/bot<token>/METHOD_NAME`.

## Key types

| Type | Prefix | Secret | Scope | Expiry |
|---|---|---|---|---|
| Bot API token | — | Yes | Full control of that one bot through the Bot API | Does not expire; replaced via @BotFather |

## How to create a Telegram key

1. Open a chat with @BotFather in Telegram.
2. Send `/newbot` and follow the prompts for a name and username.
3. BotFather replies with the bot's authentication token. Store it securely.

## Limiting what the key can do

Telegram bot tokens have no scopes: the token grants full control of that bot. Limit risk by using one bot per integration and by never putting the token in client-side code.

## How to rotate a Telegram key

1. Message @BotFather and use `/token` to generate a new token for the bot.
2. Update the new token wherever the old one was used.

## How to revoke a Telegram key

1. Revoke or replace the token through @BotFather; the bot tutorial says a token can be revoked at any time this way.

## If the key leaked

1. Replace the token through @BotFather with `/token`.
2. Update every deployment with the new token.
3. Review what the bot sent or received, since the old token could do anything the bot can.

## Gotchas

- The token is embedded in every request URL, so it can end up in logs, proxies and referrers; keep it out of them.
- Telegram says to treat the token like a password and not hardcode it in source code.
- The token has no scopes; anyone holding it can act as the bot.

## Using this key with AI agents (BotPassword)

- `run_with`: Runs a command with the key injected as an environment variable or a 0600 temporary file, never on the command line, and redacts the key from the output.
- `http_request`: Makes an authenticated API call after checking the destination against the hosts this key may be sent to. The response comes back with credential-shaped values redacted, and one that holds the key itself is refused.
- `rotate`: Partly built: creates a new key, stores it as pending, verifies it, promotes it, then revokes the old key after a grace period. Today it works for Cloudflare tokens and AWS IAM keys you have set up, and an agent can start it only under a grant with autopilot; other providers cannot be rotated through their API yet.
- `store_secret`: Saves a value the agent already holds as a new vault item.
- `capture_secret`: Planned, not built yet: will read a newly created key straight from the page or command output into the vault.

## FAQ

### How do I get a Telegram bot token?

Message @BotFather, send `/newbot`, and follow the prompts. BotFather returns the token.

### What does a Telegram bot token look like?

A numeric bot ID, a colon, then a string of letters, digits and hyphens.

### How do I regenerate a Telegram bot token?

Use `/token` in a chat with @BotFather to generate a new one.

### Can an AI agent use my Telegram key without seeing it?

Yes, if the key never enters the agent's context. Instead of pasting the key into a chat or leaving it in a `.env` file the agent can read, keep it in a credential broker that injects it into the command or request on the agent's behalf. BotPassword does this with `run_with`, `http_request`, `store_secret`, so the agent gets the result and never the value.

## Sources

- https://core.telegram.org/bots/api
- https://core.telegram.org/bots/features
- https://core.telegram.org/bots/tutorial
