Skip to content

Telegram Bot ​

You can call the DDTokens API from your own Telegram Bot backend. DDTokens does not require a particular Bot framework as long as the backend can send HTTP requests.

Basic Architecture ​

text
Telegram user -> Bot backend -> DDTokens API -> Model response -> Bot backend -> Telegram user

The Bot backend stores the Telegram Bot Token, DDTokens API key, conversation context, and error-handling logic.

Environment Variables ​

bash
export TELEGRAM_BOT_TOKEN="your-telegram-bot-token"
export DDDT_API_KEY="sk-your-key-here"
export DDDT_BASE_URL="https://apiddt.com/v1"
export DDDT_MODEL="gpt-4o-mini"

Recommendations ​

  • Create a dedicated DDTokens API key for the Bot.
  • Set a token quota so a public Bot cannot exhaust the account balance.
  • Rate-limit each user.
  • Record the request ID, Telegram user ID, model, and cost.
  • Never store a complete API key in logs.

Common Issues ​

Bot Does Not Reply ​

First check that the Telegram Bot Token is valid, then verify that the backend called the DDTokens API successfully.

Unexpected Cost Increase ​

Check Usage Logs for the request source, model, and token usage. If necessary, disable the API key used by the Bot first.

Replies Are Too Slow ​

Reduce the maximum output length or switch to a faster model. Long replies can use streaming responses, but the Bot backend must support sending them in segments.

© 2026 DDTokens