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 તેની મર્યાદા પર હોય, ત્યારે વપરાશકર્તાને પછી ફરી પ્રયાસ કરવા કહો.
આ મફત મોડેલ આજે માપેલી સૌથી ઝડપી ગતિ ધરાવે છે. તેમાંથી ઘણાની વિનંતી મર્યાદા ઊંચી છે:
| મૉડેલ | મફત ઉપલબ્ધ | સંદર્ભ | મફત મર્યાદા (શ્રેષ્ઠ ઑફર) | સાધનો | વિઝન |
|---|---|---|---|---|---|
| Qwen3.8 27B | BlazeAPI, ElectronHub, Gizmo +3 વધુ | 262K | 30 વિનંતી/મિનિટ 250 વિનંતી/દિવસ 70,000 ટોકન/મિનિટ ~6M | હા | હા |
| GPT-OSS 20B | Api.Airforce, Cloudflare Workers AI, Groq +4 વધુ | 131K | 30 વિનંતી/મિનિટ 1,000 વિનંતી/દિવસ 8,000 ટોકન/મિનિટ 200,000 ટોકન/દિવસ ~6M | હા | ના |
| Nemotron 3.5 Lightning | ElectronHub, Gizmo, Kilo Gateway +2 વધુ | 1M | 20 વિનંતી/મિનિટ 50 વિનંતી/દિવસ 50 req/day account-wide (1,000 after a $10 purchase) | હા | ના |
| GPT-OSS 120B | Cloudflare Workers AI, ElectronHub, Groq +1 વધુ | 131K | 30 વિનંતી/મિનિટ 1,000 વિનંતી/દિવસ 8,000 ટોકન/મિનિટ 200,000 ટોકન/દિવસ ~6M | હા | ના |
| GPT-OSS 20B (via Groq) | DreamPrompting | 131K | 100 વિનંતી/મિનિટ 5,000 વિનંતી/દિવસ 500,000 ટોકન/દિવસ 500K tokens/day · 5,000 req/day | ના | ના |
| GPT-OSS Safeguard 20B | Groq | 131K | 30 વિનંતી/મિનિટ 1,000 વિનંતી/દિવસ 8,000 ટોકન/મિનિટ 200,000 ટોકન/દિવસ ~6M | હા | ના |
| Groq Compound Mini | DreamPrompting | 131K | 100 વિનંતી/મિનિટ 5,000 વિનંતી/દિવસ 500,000 ટોકન/દિવસ 500K tokens/day · 5,000 req/day | ના | ના |
| Gemini 3.5 Flash Lite | ElectronHub, Google AI Studio | 1M | 15 વિનંતી/મિનિટ 20 વિનંતી/દિવસ 250,000 ટોકન/મિનિટ ~3M | હા | હા |
| Step 3.7 Flash | ElectronHub | 256K | $0.25/week shared recurring credit | હા | હા |
| Gemini 3.1 Flash-Lite | DreamPrompting, Google AI Studio | 1M | 100 વિનંતી/મિનિટ 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
- Discord Developer Portal ખોલો અને application બનાવો. bot ઉમેરો અને તેનો token કૉપી કરો.
- bot tab પર, Privileged Gateway Intents પર જાઓ. Message Content ચાલુ કરો.
botscope અને Send Messages permission સાથે bot ને તમારા server માં આમંત્રિત કરો.DISCORD_TOKENenvironment 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
- Telegram માં @BotFather ખોલો અને
/newbotમોકલો. token કૉપી કરો. TELEGRAM_TOKENenvironment variable માં token સેટ કરો.- 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 બનાવે છે.
| Agent | Setup આદેશ | તે શું લખે છે |
|---|---|---|
| OpenClaw | npx freellmapi setup-openclaw --url http://localhost:3001 --api-key <unified-key> | freellmapi provider, ~/.openclaw/openclaw.json માં, ડિફોલ્ટ મોડેલ freellmapi/auto |
| Hermes Agent | npx 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 થાય છે. |
| ધીમા જવાબ | ધીમું મોડેલ અથવા લાંબો history | auto:fast વાપરો અને 10 કે ઓછા સંદેશ રાખો |
bot તરફથી Connection refused | bot Docker માં ચાલે છે અને localhost વાપરે છે | host.docker.internal અથવા સહિયારું Docker network વાપરો |
વારંવાર પૂછાતા પ્રશ્નો
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 કોડ તેને પકડે છે અને વપરાશકર્તાને પછી ફરી પ્રયાસ કરવા કહે છે.
સંબંધિત માર્ગદર્શિકાઓ
- Python માં મફત LLM API
- મફત LLM API rate limits
- મફત OpenAI સાથે સુસંગત API base URL
- AI એજન્ટ્સ માટે મફત LLM API
- કાર્ડ વગર મફત LLM API
સ્રોતો
- discord.py docs: quickstart (તપાસ્યું 20 November 2026)
- discord.py docs: privileged intents (તપાસ્યું 20 November 2026)
- Discord developer docs: message resource (2000 character content limit) (તપાસ્યું 20 November 2026)
- python-telegram-bot v22 docs: echobot example (તપાસ્યું 20 November 2026)
- Telegram Bot API: sendMessage and sendChatAction (તપાસ્યું 20 November 2026)
- FreeLLMAPI docs: clients (OpenClaw, Hermes Agent, context handoff) (તપાસ્યું 20 November 2026)