A private Telegram (and optional Discord) bot that you run yourself. It generates images and videos, turns images into videos, and lets you chat with characters you define, all paid from your own SpicyAPI balance, with spending limits that are checked before anything is charged.
- Images:
/pic a lighthouse at dusk - Videos:
/vid waves rolling onto a beach at sunset - Animate: tap Animate under any image the bot made, or reply to it with
/animate <how it should move> - Character chat: just type in a private chat, or use
/talk. Replies stream into one message. - Spend protection: every request is priced first (free), expensive ones need a tap on Confirm, and per-person and whole-bot daily limits are enforced.
- Private by default: only you can use it until you allow other people or groups.
SpicyAPI's catalogue includes uncensored models that add no content filter of their own; the bot works with any of them. The law and SpicyAPI's content policy still apply to everything you generate.
You need a computer or server that stays on, with Docker installed.
1. Get a SpicyAPI key. In the SpicyAPI console, create a new API key just for this bot. Give that key a daily spend cap (and, if you like, a list of allowed models). The bot has its own limits too, but the key's cap is enforced by SpicyAPI itself, so it holds even if the bot is misconfigured or its data is lost. New keys have no cap unless you set one.
2. Create a Telegram bot. Open @BotFather, send /newbot, pick a name
and a username, and copy the token it gives you.
3. Configure.
git clone https://github.com/spicyapi-ai/spicyapi-bot.git
cd spicyapi-bot
cp .env.example .envOpen .env and fill in the three required lines:
SPICY_API_KEY=sk-spicy-...
TELEGRAM_BOT_TOKEN=123456789:AA...
OWNER_ID=your-telegram-user-idDon't know your Telegram user ID? Put OWNER_ID=0 for now, finish step 4, send your bot any
message, and it will reply with your ID. Then set it and restart.
4. Start.
docker compose up -d --build
docker compose logs -f # "Telegram bot @yourbot is running"5. Try it. Open your bot in Telegram, send /start, accept the rules once, and send
/pic a cozy cabin in the snow. The default image model costs about $0.01 per image.
To update later: git pull && docker compose up -d --build.
Railway can run the bot without a server of your own.
- Fork this repository to your GitHub account.
- In Railway: New Project → Deploy from GitHub repo, and pick your fork. Railway finds the
Dockerfileand builds it. - Open the service's Variables tab and add
SPICY_API_KEY,TELEGRAM_BOT_TOKENandOWNER_ID(plus any other setting from.env.example). - Right-click the service → Attach volume, mount path
/data. Without a volume, every redeploy forgets today's spending and everyone's settings. - Deploy. The logs should show
Telegram bot @yourbot is running.
Keep the service at one replica: two copies polling the same Telegram token fight over updates. The bot needs no public domain and no open port.
- In the Discord Developer Portal, create an application, open Bot, reset and copy the token, and turn Public Bot off so only you can add it to servers. No privileged intents are needed.
- Under OAuth2 → URL Generator, tick the scopes
botandapplications.commands, and the permissions Send Messages, Attach Files, Embed Links and Read Message History. Open the generated link and add the bot to your server. - Set
DISCORD_TOKENin.env(andDISCORD_GUILD_IDwith your server ID if you want the commands to appear instantly), add your Discord user ID toOWNER_ID(e.g.OWNER_ID=tg:123,dc:456), and add the channel or server ID toALLOWED_CHAT_IDS. - Images and videos only work in age-restricted channels: Edit Channel → Overview →
Age-Restricted Channel. The
/picand/vidcommands are registered as age-restricted, so Discord only shows them there. Chat (/talk, or mentioning the bot) works in any allowed channel unless you setDISCORD_CHAT_REQUIRES_NSFW=true.
Discord does not allow apps with age-restricted commands in its App Directory, so keep the bot private. To find IDs, turn on Developer Mode (User Settings → Advanced) and right-click a user, channel or server → Copy ID.
| Command | What it does |
|---|---|
/pic <prompt> |
Generate an image |
/vid <prompt> |
Generate a video from text |
/animate <motion> |
Reply to an image to turn it into a video. Images the bot made always work; your own photos only if the operator set ALLOW_PHOTO_UPLOADS=true |
| Animate button | Under every generated image: animates it, reusing its prompt |
/talk <message> |
Talk to the current character (in a private chat you can simply type) |
/persona |
Choose a character |
/newchat |
Forget the conversation and start over |
/models |
Choose your image, video, animate and chat models |
/spend |
What you have spent today; the owner also sees the whole bot and the account balance |
/report <text> |
Send a report to the operator |
/help |
Summary of all of this |
The names are deliberately not /image, /video or /chat, which other popular bots use, so the
bot can share a group with them. In a Telegram group, reply to one of the bot's chat messages to keep
talking to the character.
- Price first. Each image or video is quoted by SpicyAPI before anything happens. Quotes are free.
- Hard ceiling. If a request could cost more than
MAX_COST_PER_REQUEST_USD(default $1), it is refused. Nothing is charged. - Confirmation. If it could cost more than
CONFIRM_ABOVE_USD(default $0.10), the bot shows the price with Confirm and Cancel buttons. Only the person who asked can confirm. - Daily limits. Each person may spend
USER_DAILY_BUDGET_USD(default $1) per UTC day, the whole botDAILY_BUDGET_USD(default $5). Generations still running count as spent until they finish, so several requests at once cannot slip past a limit. Owners are only bound by the whole-bot limit. - No double charges. Each request carries an idempotency key derived from the chat message or button tap, so a duplicated Telegram update or a double tap returns the task that already exists.
- Results. Progress is shown by editing one message every few seconds. The result shows the actual charge and the task ID, which you can look up under Logs in the SpicyAPI console.
A generation that has started cannot be cancelled; it finishes and is charged. Failed
generations are not charged. The bot's ledger lives in DATA_DIR/state.json; the key's spend cap in
the SpicyAPI console is the limit that can never be lost.
- Private by default. Strangers who find the bot are told it is private and given their user ID
to send you. Groups are ignored until listed in
ALLOWED_CHAT_IDS; once listed, every member can use the bot. SettingALLOWED_USER_IDS=*makes the bot public and lets anyone spend your balance. - Rules first. Everyone confirms once that they are 18+ and will not create content involving
minors, sexual content of real people, or impersonation (
REQUIRE_CONSENT). - Spoilers. In groups, results are hidden behind a spoiler (
SPOILER_MEDIA). - Uploaded photos are off by default. Turning photos of real people into videos is the main way
bots like this get abused, so by default only images the bot generated can be animated. If you
enable
ALLOW_PHOTO_UPLOADS, uploaded images are downloaded by the bot and stored with SpicyAPI; Telegram file links are never passed on, because they contain your bot token. - What is stored.
state.jsonholds daily spend totals, each person's model and character choice, and who accepted the rules. Chat history is kept in memory only, forgotten on restart, after a day of inactivity, or with/newchat. Logs contain task IDs and amounts, never prompts or media. SetRETENTION_SECONDSto have SpicyAPI delete results and prompts sooner than your account default. - Reports.
/reportforwards a message to the owner. Content that breaks SpicyAPI's rules can also be reported at spicyapi.ai/abuse.
You operate this bot and are responsible for who you let use it. SpicyAPI's terms apply, including the regions it does not serve.
Characters live in a JSON file (CHARACTERS_FILE, default characters/default.json, which has two
example characters):
{
"characters": [
{
"id": "mira",
"name": "Mira",
"system": "You are Mira, ... Never speak or act for {{user}}.",
"greeting": "Welcome aboard, {{user}}!",
"model": "deepseek/v4.1-flash/chat"
}
]
}systemis the character's instructions;greeting(optional) is their first line;model(optional) pins a chat model for this character.{{char}}and{{user}}are replaced with the character's name and the person's first name.- Character cards: entries can also be Character Card V2 JSON (the format most character sites and SillyTavern export). The description, personality, scenario, example dialogue and first message are used.
With Docker, mount your own file and point the setting at it (see docker-compose.yml):
volumes:
- ./my-characters.json:/app/characters/custom.json:roCHARACTERS_FILE=characters/custom.jsonEvery setting is an environment variable; .env.example explains each one. The most useful:
| Variable | Default | |
|---|---|---|
SPICY_API_KEY |
required | Your key (sk-spicy-...) |
TELEGRAM_BOT_TOKEN / DISCORD_TOKEN |
one required | Which platforms to run |
OWNER_ID |
required | Your user ID(s); tg: / dc: prefixes pin a platform |
ALLOWED_USER_IDS |
empty | Other people allowed in private chats |
ALLOWED_CHAT_IDS |
empty | Groups, channels or servers where the bot answers |
DAILY_BUDGET_USD / USER_DAILY_BUDGET_USD |
5 / 1 |
Daily limits (UTC) |
MAX_COST_PER_REQUEST_USD / CONFIRM_ABOVE_USD |
1 / 0.10 |
Per-request ceiling and confirmation threshold |
DEFAULT_IMAGE_MODEL |
alibaba/z-image-turbo/text-to-image |
About $0.01 per image |
DEFAULT_VIDEO_MODEL / DEFAULT_ANIMATE_MODEL |
minimax/h3/... |
About $0.025 per second at 480p |
DEFAULT_CHAT_MODEL |
deepseek/v4.1-flash/chat |
Any chat model in the catalogue |
VIDEO_SECONDS / VIDEO_RESOLUTION |
5 / 480p |
Snapped to what each model allows |
ALLOW_PHOTO_UPLOADS |
false |
Animate photos people upload |
DATA_DIR |
./data (/data in Docker) |
Where state.json lives |
Prices are from the public catalogue at the time of writing; the bot always shows the live quote. Browse models at spicyapi.ai/models.
| Message or symptom | What to do |
|---|---|
"out of balance" (40201) |
Top up your SpicyAPI balance |
"reached the spend cap" (40202) |
The key's cap in the console was reached; raise it or wait |
"not allowed to use that model" (40301) |
Allow the model on the key in the console, or pick another with /models |
"has not verified its email" (40310) |
Open the verification link from SpicyAPI |
| "The model declined this request" | That model refused the prompt; reword it or pick another model. Not charged |
Conflict: terminated by other getUpdates request |
Two copies of the bot use the same token. Stop one |
| Discord commands missing | /pic and /vid only show in age-restricted channels. Global commands can take a moment to appear; set DISCORD_GUILD_ID for instant registration |
| Network errors behind a proxy | Node's fetch ignores HTTPS_PROXY unless started with NODE_USE_ENV_PROXY=1 |
Requires Node.js 22.13 or newer.
npm ci
npm run check # typecheck, lint, tests
npm run dev # build and run with .envThe tests use fakes for SpicyAPI and a stand-in Telegram Bot API, so they need no keys or network.
npm run live-check runs the core flow against the real API with SPICY_API_KEY (one image, one
480p image-to-video, two chat turns; about $0.12) without Telegram or Discord.
Built on grammY, discord.js, the official
@spicyapi/sdk for media and the official
openai package for chat, pointed at
https://api.spicyapi.ai/v1.
MIT