હોમ / માર્ગદર્શિકાઓ / Discord અથવા Telegram bot માટે મફત AI API

Discord અથવા Telegram bot માટે મફત AI API

chat bot દરેક સંદેશ માટે એક મોડેલ વિનંતી મોકલે છે. વ્યસ્ત server માં એક મફત ટિયર મિનિટોમાં તેની મર્યાદા પર પહોંચે છે. આ માર્ગદર્શિકા Discord bot અને Telegram bot ને FreeLLMAPI સાથે જોડે છે. FreeLLMAPI એક OpenAI-compatible key પાછળ 45 મફત પ્રદાતા ટિયર એકત્રિત કરે છે, અને મર્યાદા વિનંતીને રોકે ત્યારે આગલા પ્રદાતા પર જાય છે. કોડ Python માં છે અને સંપૂર્ણ છે.

કોડ, મૉડેલ નામ અને લાઇવ કૅટલૉગ લેબલ અંગ્રેજીમાં બતાવવામાં આવે છે.

પહેલા મર્યાદાનું આયોજન કરો

મફત ટિયર પ્રતિ મિનિટ અને પ્રતિ દિવસ વિનંતી મર્યાદિત કરે છે. 200 સક્રિય વપરાશકર્તાવાળા server માં bot દરરોજ હજારો વિનંતી મોકલી શકે છે. failover આ વિનંતીઓને તમારી બધી keys પર વહેંચે છે, પરંતુ કુલ સંખ્યા હજી પણ મફત મર્યાદાનો સરવાળો છે.

  • ફક્ત પૂછવામાં આવે ત્યારે જવાબ આપો. Discord માં ફક્ત mentions નો જવાબ આપો. Telegram groups માં ફક્ત commands અથવા replies નો જવાબ આપો.
  • દરેક વપરાશકર્તાને મર્યાદિત કરો. દર થોડી સેકન્ડે દરેક વપરાશકર્તા માટે એક વિનંતી મંજૂર કરો.
  • history ટૂંકી રાખો. આખો channel history નહીં, છેલ્લા 10 સંદેશ મોકલો.
  • ઝડપી route વાપરો. auto:fast મોડેલને ઝડપ પ્રમાણે ક્રમ આપે છે. chat વપરાશકર્તાઓ ઓછી રાહ જુએ છે.
  • વિનમ્ર રીતે નિષ્ફળ થાઓ. જ્યારે દરેક key તેની મર્યાદા પર હોય, ત્યારે વપરાશકર્તાને પછી ફરી પ્રયાસ કરવા કહો.
ગોપનીયતા: bot વપરાશકર્તાના સંદેશ જવાબ આપનાર પ્રદાતાને મોકલે છે. કેટલાક મફત ટિયર તેમના મોડેલ સુધારવા prompts નો ઉપયોગ કરી શકે છે. તમારા વપરાશકર્તાઓને કહો કે એક AI સેવા તેમના સંદેશ વાંચે છે. કયા મફત LLM APIs તમારા ડેટા પર તાલીમ લે છે વાંચો, અને તમે સ્વીકારતા ન હો તે પ્રદાતાઓને તમારી chain માંથી દૂર કરો.

આ મફત મોડેલ આજે માપેલી સૌથી ઝડપી ગતિ ધરાવે છે. તેમાંથી ઘણાની વિનંતી મર્યાદા ઊંચી છે:

ઝડપી મફત chat મોડેલ
મૉડેલમફત ઉપલબ્ધસંદર્ભમફત મર્યાદા (શ્રેષ્ઠ ઑફર)સાધનોવિઝન
Qwen3.8 27BBlazeAPI, ElectronHub, Gizmo +3 વધુ262K30 વિનંતી/મિનિટ
250 વિનંતી/દિવસ
70,000 ટોકન/મિનિટ
~6M
હાહા
GPT-OSS 20BApi.Airforce, Cloudflare Workers AI, Groq +4 વધુ131K30 વિનંતી/મિનિટ
1,000 વિનંતી/દિવસ
8,000 ટોકન/મિનિટ
200,000 ટોકન/દિવસ
~6M
હાના
Nemotron 3.5 LightningElectronHub, Gizmo, Kilo Gateway +2 વધુ1M20 વિનંતી/મિનિટ
50 વિનંતી/દિવસ
50 req/day account-wide (1,000 after a $10 purchase)
હાના
GPT-OSS 120BCloudflare Workers AI, ElectronHub, Groq +1 વધુ131K30 વિનંતી/મિનિટ
1,000 વિનંતી/દિવસ
8,000 ટોકન/મિનિટ
200,000 ટોકન/દિવસ
~6M
હાના
GPT-OSS 20B (via Groq)DreamPrompting131K100 વિનંતી/મિનિટ
5,000 વિનંતી/દિવસ
500,000 ટોકન/દિવસ
500K tokens/day · 5,000 req/day
નાના
GPT-OSS Safeguard 20BGroq131K30 વિનંતી/મિનિટ
1,000 વિનંતી/દિવસ
8,000 ટોકન/મિનિટ
200,000 ટોકન/દિવસ
~6M
હાના
Groq Compound MiniDreamPrompting131K100 વિનંતી/મિનિટ
5,000 વિનંતી/દિવસ
500,000 ટોકન/દિવસ
500K tokens/day · 5,000 req/day
નાના
Gemini 3.5 Flash LiteElectronHub, Google AI Studio1M15 વિનંતી/મિનિટ
20 વિનંતી/દિવસ
250,000 ટોકન/મિનિટ
~3M
હાહા
Step 3.7 FlashElectronHub256K$0.25/week shared recurring creditહાહા
Gemini 3.1 Flash-LiteDreamPrompting, Google AI Studio1M100 વિનંતી/મિનિટ
5,000 વિનંતી/દિવસ
500,000 ટોકન/દિવસ
500K tokens/day · 5,000 req/day
હાહા

મેળ ખાતા 215 મફત મૉડેલમાંથી 10 બતાવ્યા. બધા મૉડેલ જુઓ.

FreeLLMAPI કૅટલૉગનો લાઇવ ડેટા (સંસ્કરણ 2026.11.19, તપાસ્યું 2026-11-19). મફત મર્યાદાઓ વારંવાર બદલાય છે. કૅટલૉગ દરરોજ તપાસવામાં આવે છે.

સહિયારો કોડ: મોડેલ કૉલ

બંને bots એક જ module વાપરે છે. તે દરેક chat માટે ટૂંકો history રાખે છે, દરેક chat માટે એક session ID મોકલે છે અને rate limits સંભાળે છે. પહેલા FreeLLMAPI ઇન્સ્ટોલ કરો અને ડેશબોર્ડના Keys પેજ પરથી unified key કૉપી કરો.

ઇન્સ્ટોલ

curl -fsSL https://freellmapi.co/install.sh | bash

python3 -m pip install -U openai discord.py python-telegram-bot
export FREELLMAPI_API_KEY=<unified-key>

brain.py

import asyncio
import os
import time
from collections import defaultdict, deque

import openai
from openai import AsyncOpenAI

llm = AsyncOpenAI(
    base_url="http://localhost:3001/v1",
    api_key=os.environ["FREELLMAPI_API_KEY"],
    max_retries=2,
    timeout=60,
)

SYSTEM = "You are a helpful chat bot. Answer in short paragraphs."
history = defaultdict(lambda: deque(maxlen=10))  # chat id -> last 10 messages
last_call = {}  # user id -> time of the last request
COOLDOWN_S = 5

async def ask(chat_id: str, user_id: str, text: str) -> str:
    now = time.monotonic()
    if now - last_call.get(user_id, 0) < COOLDOWN_S:
        return "Please wait a few seconds before the next question."
    last_call[user_id] = now

    turns = history[chat_id]
    turns.append({"role": "user", "content": text[:4000]})
    messages = [{"role": "system", "content": SYSTEM}, *turns]

    for attempt in range(3):
        try:
            resp = await llm.chat.completions.create(
                model="auto:fast",
                messages=messages,
                max_tokens=800,
                extra_headers={"X-Session-Id": f"chat-{chat_id}"},
            )
            answer = resp.choices[0].message.content or "(no answer)"
            turns.append({"role": "assistant", "content": answer})
            return answer
        except openai.RateLimitError as err:
            header = err.response.headers.get("retry-after", "")
            wait = int(header) if header.isdigit() else 2 ** attempt
            if wait > 30:
                break
            await asyncio.sleep(wait)
        except openai.APIError:
            break
    turns.pop()  # forget the unanswered question
    return "All free models are busy now. Please try again later."

def split(text: str, size: int) -> list[str]:
    return [text[i:i + size] for i in range(0, len(text), size)] or [""]

X-Session-Id header એક chat ને 30 મિનિટ સુધી એક મોડેલ પર રાખે છે. પછી bot વાતચીતમાં એ જ શૈલી રાખે છે. જો તે મોડેલ તેની મર્યાદા પર પહોંચે, તો રાઉટર બીજા મોડેલ પર જાય છે, જે એ જ history મેળવે છે.

history અને cooldowns memory માં રહે છે. bot restart થાય ત્યારે તે ખોવાઈ જાય છે. જે bot લાંબી વાતચીત યાદ રાખવી જ જોઈએ, તેના માટે history ને SQLite અથવા Redis જેવા database માં સાચવો.

discord.py સાથે Discord bot

  1. Discord Developer Portal ખોલો અને application બનાવો. bot ઉમેરો અને તેનો token કૉપી કરો.
  2. bot tab પર, Privileged Gateway Intents પર જાઓ. Message Content ચાલુ કરો.
  3. bot scope અને Send Messages permission સાથે bot ને તમારા server માં આમંત્રિત કરો.
  4. DISCORD_TOKEN environment variable માં token સેટ કરો અને script ચલાવો.

discord_bot.py

import os

import discord

from brain import ask, split

intents = discord.Intents.default()
intents.message_content = True
client = discord.Client(intents=intents)

@client.event
async def on_ready():
    print(f"Logged in as {client.user}")

@client.event
async def on_message(message: discord.Message):
    if message.author.bot or client.user not in message.mentions:
        return
    text = message.content
    for tag in (f"<@{client.user.id}>", f"<@!{client.user.id}>"):
        text = text.replace(tag, "")
    text = text.strip()
    if not text:
        return
    async with message.channel.typing():
        answer = await ask(str(message.channel.id), str(message.author.id), text)
    parts = split(answer, 2000)  # Discord limit: 2000 characters
    await message.reply(parts[0])
    for part in parts[1:]:
        await message.channel.send(part)

client.run(os.environ["DISCORD_TOKEN"])

python-telegram-bot સાથે Telegram bot

  1. Telegram માં @BotFather ખોલો અને /newbot મોકલો. token કૉપી કરો.
  2. TELEGRAM_TOKEN environment variable માં token સેટ કરો.
  3. script ચલાવો. તમારા bot ને સંદેશ મોકલો.

telegram_bot.py

import os

from telegram import Update
from telegram.constants import ChatAction
from telegram.ext import Application, ContextTypes, MessageHandler, filters

from brain import ask, split

async def on_text(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
    chat_id = update.effective_chat.id
    await context.bot.send_chat_action(chat_id=chat_id, action=ChatAction.TYPING)
    answer = await ask(str(chat_id), str(update.effective_user.id), update.message.text)
    for part in split(answer, 4096):  # Telegram limit: 4096 characters
        await update.message.reply_text(part)

def main() -> None:
    app = Application.builder().token(os.environ["TELEGRAM_TOKEN"]).build()
    app.add_handler(MessageHandler(filters.TEXT & ~filters.COMMAND, on_text))
    app.run_polling(allowed_updates=Update.ALL_TYPES)

if __name__ == "__main__":
    main()

Telegram માં typing સ્થિતિ 5 સેકન્ડ કે ઓછી રહે છે. ધીમા મોડેલ માટે લાંબી વિનંતી દરમિયાન chat action ફરી મોકલો. કોડ python-telegram-bot version 22 વાપરે છે, જે સંપૂર્ણપણે async છે.

તૈયાર bot agents

જો તમે bot લખવા ન માંગતા હો, તો બે agents Discord અને Telegram પર જવાબ આપી શકે છે અને તેમનું મોડેલ તરીકે FreeLLMAPI વાપરે છે. FreeLLMAPI દરેક માટે એક setup આદેશ આપે છે. દરેક આદેશ --dry-run ને સપોર્ટ કરે છે અને પહેલા configuration નો backup બનાવે છે.

AgentSetup આદેશતે શું લખે છે
OpenClawnpx freellmapi setup-openclaw --url http://localhost:3001 --api-key <unified-key>freellmapi provider, ~/.openclaw/openclaw.json માં, ડિફોલ્ટ મોડેલ freellmapi/auto
Hermes Agentnpx freellmapi setup-hermes --url http://localhost:3001 --api-key <unified-key>~/.hermes/config.yaml માં custom model block

ચાલતા OpenClaw અથવા Hermes gateway ને setup આદેશ પછી restart ની જરૂર પડે છે.

bot અને FreeLLMAPI ને એક જ કમ્પ્યુટર અથવા server પર ચલાવો. પછી bot localhost પર gateway સુધી પહોંચે છે, અને gateway port internet માટે બંધ રહે છે. બંને માટે એક નાનો server અથવા Raspberry Pi પૂરતું છે.

સમસ્યાનિવારણ

સમસ્યાકારણઉકેલ
Discord bot ખાલી સંદેશ વાંચે છેMessage Content intent બંધ છેportal માં અને intents.message_content માં તે ચાલુ કરો
bot પોતાના સંદેશનો જવાબ આપે છેbot લેખકો માટે કોઈ તપાસ નથીmessage.author.bot સાચું હોય ત્યારે પાછા ફરો
લાંબા જવાબ પર Discord error 50035સંદેશ 2000 અક્ષર કરતાં લાંબો છેઉપરના કોડની જેમ જવાબ વિભાજિત કરો
સાંજે "All free models are busy"chain ની બધી keys તેમની દૈનિક મર્યાદા પર છેવધુ પ્રદાતાઓની keys ઉમેરો. ઘણી દૈનિક મર્યાદા UTC મધ્યરાત્રિએ reset થાય છે.
ધીમા જવાબધીમું મોડેલ અથવા લાંબો historyauto:fast વાપરો અને 10 કે ઓછા સંદેશ રાખો
bot તરફથી Connection refusedbot Docker માં ચાલે છે અને localhost વાપરે છેhost.docker.internal અથવા સહિયારું Docker network વાપરો
આ બધાનો ઉપયોગ એક જ કી દ્વારા કરો. FreeLLMAPI એક ઓપન-સોર્સ, સ્વ-હોસ્ટેડ રાઉટર છે. તે આ બધા મફત ટાયરને એક OpenAI સાથે સુસંગત એન્ડપોઇન્ટ પાછળ મૂકે છે અને જ્યારે એક મૉડેલની રેટ મર્યાદા આવે ત્યારે બીજા પર આપમેળે સ્વિચ કરે છે. કૅટલૉગ બ્રાઉઝ કરો અથવા લાઇવ જાઓ.

વારંવાર પૂછાતા પ્રશ્નો

Discord bot માટે મફત AI API છે?

હા. ઘણા પ્રદાતા પાસે મફત ટિયર છે જે openai Python package સાથે કામ કરે છે. FreeLLMAPI તેમને એક key પાછળ ભેગા કરે છે, તેથી વ્યસ્ત bot ઘણા પ્રદાતાઓની મર્યાદા વાપરી શકે છે.

શું હું મફત AI Telegram bot બનાવી શકું?

હા. bot માટે python-telegram-bot અને જવાબ માટે OpenAI-compatible મફત API વાપરો. આ પેજનો કોડ સંપૂર્ણ છે.

મારા AI bot ને rate limits સુધી પહોંચતો કેવી રીતે રોકું?

ફક્ત mentions અથવા commands નો જવાબ આપો, દર થોડી સેકન્ડે દરેક વપરાશકર્તાને એક વિનંતી સુધી મર્યાદિત કરો, history ટૂંકી રાખો અને વધુ પ્રદાતાઓની keys ઉમેરો.

મારા Discord bot ને ખાલી message content કેમ મળે છે?

Message Content intent બંધ છે. Developer Portal માં bot tab પર તે ચાલુ કરો, અને કોડમાં intents.message_content = True સેટ કરો.

જ્યારે બધા મફત મોડેલ તેમની મર્યાદા પર હોય ત્યારે શું થાય છે?

FreeLLMAPI Retry-After header સાથે error 429 પરત કરે છે. bot કોડ તેને પકડે છે અને વપરાશકર્તાને પછી ફરી પ્રયાસ કરવા કહે છે.

સંબંધિત માર્ગદર્શિકાઓ

સ્રોતો

બધી માર્ગદર્શિકાઓ · બધા મફત મૉડેલ જુઓ