Free LLM API สำหรับ RAG
Retrieval-augmented generation (RAG) ต้องใช้ API สองตัว ได้แก่ โมเดล embedding เพื่อหาข้อความที่เกี่ยวข้อง และโมเดลแชตเพื่อเขียนคำตอบ ทั้งสองมีให้ใช้ในแพ็กเกจฟรี FreeLLMAPI ให้คีย์ OpenAI-compatible เพียงคีย์เดียวสำหรับโมเดล embedding ฟรี 41 รายการ และโมเดลแชตฟรี 487 รายการ พร้อมการสลับสำรองระหว่างผู้ให้บริการ คู่มือนี้แสดงโมเดลฟรีสำหรับแต่ละขั้นตอน และไปป์ไลน์ Python ที่สมบูรณ์
โค้ด ชื่อโมเดล และป้ายกำกับของแคตตาล็อกสดจะแสดงเป็นภาษาอังกฤษ
ไปป์ไลน์ RAG บนแพ็กเกจฟรี
| ขั้นตอน | API | ข้อควรระวังของแพ็กเกจฟรี |
|---|---|---|
| 1. แบ่งเอกสารเป็น chunk | ไม่มี (โค้ดในเครื่อง) | ไม่มี |
| 2. embed แต่ละ chunk | /v1/embeddings | คำขอจำนวนมากตอนเริ่มต้น แพ็กเกจ embedding ฟรีบางรายอนุญาต 10 คำขอต่อนาที |
| 3. embed คำถาม | /v1/embeddings | หนึ่งคำขอต่อคำถาม |
| 4. หา chunk ที่ตรงที่สุด | ไม่มี (การค้นหาเวกเตอร์ในเครื่อง) | ไม่มี |
| 5. จัดอันดับ chunk ใหม่ (ไม่บังคับ) | /v1/chat/completions | หนึ่งคำขอแชตเพิ่มต่อคำถาม |
| 6. เขียนคำตอบ | /v1/chat/completions | พรอมต์ขนาดใหญ่ ใช้ขีดจำกัดโทเค็นต่อนาที |
ขั้นตอนที่ 2 เป็นขั้นตอนที่ใช้ทรัพยากรมากที่สุด ทำครั้งเดียวต่อหนึ่งเอกสาร บันทึกเวกเตอร์ไว้ และภายหลัง embed เฉพาะเอกสารที่ใหม่หรือมีการเปลี่ยนแปลง
ติดตั้ง FreeLLMAPI และแพ็กเกจ Python
curl -fsSL https://freellmapi.co/install.sh | bash
python3 -m pip install -U openai numpy
export FREELLMAPI_API_KEY=<unified-key>เลือกโมเดล embedding ฟรี
เลือกตระกูล embedding หนึ่งตระกูลและใช้ตลอดทั้งดัชนี เวกเตอร์จากสองโมเดลไม่เข้ากัน FreeLLMAPI ป้องกันการผสมเวกเตอร์: การสลับสำรองของ embedding จะไม่เปลี่ยนโมเดล ระบบย้ายไปยังผู้ให้บริการที่ให้บริการตระกูลเดียวกันเท่านั้น
| โมเดล | ผู้ให้บริการ | มิติ | อินพุตสูงสุด | ขีดจำกัดฟรี |
|---|---|---|---|---|
Gemini Embeddinggemini-embedding-001 | Google AI Studio | 3072 | 2048 | 100 rpm · 1K req/day |
Nemotron Embed VL 1Bnvidia/llama-nemotron-embed-vl-1b-v2 | NVIDIA NIM | 2048 | 8192 | ~40 rpm |
Nemotron 3 Embed 1B (OR free)nvidia/nemotron-3-embed-1b:free | OpenRouter | 2048 | 32768 | 20 rpm · shared free daily cap |
SEA-LION E5 Embedding 600Maisingapore/SEA-LION-E5-Embedding-600M | SEA-LION | 1024 | 8192 | free · 10 rpm |
SEA-LION ModernBERT Embedding 300Maisingapore/SEA-LION-ModernBERT-Embedding-300M | SEA-LION | 1024 | 8192 | free · 10 rpm |
SEA-LION ModernBERT Embedding 600Maisingapore/SEA-LION-ModernBERT-Embedding-600M | SEA-LION | 1024 | 8192 | free · 10 rpm |
BGE-M3@cf/baai/bge-m3 | Cloudflare Workers AI | 1024 | 8192 | 10K neurons/day (shared) |
EmbeddingGemma 300M@cf/google/embeddinggemma-300m | Cloudflare Workers AI | 768 | 2048 | 10K neurons/day (shared) |
Qwen3 Embedding 0.6B@cf/qwen/qwen3-embedding-0.6b | Cloudflare Workers AI | 1024 | 8192 | 10K neurons/day (shared) |
Cohere Embed v4embed-v4.0 | Cohere | 1536 | 128000 | 1K calls/mo (shared w/ chat) |
Gemini Embedding 2gemini-embedding-2 | Google AI Studio | 3072 | 8192 | free-tier rate limited |
Nemotron 3 Embed 1Bnvidia/nemotron-3-embed-1b | NVIDIA NIM | 2048 | 4096 | ~40 rpm |
PLaMo Embedding 1B (CF)@cf/pfnet/plamo-embedding-1b | Cloudflare Workers AI | 2048 | 4096 | 10K neurons/day (shared) |
BGE Small EN v1.5 (CF)@cf/baai/bge-small-en-v1.5 | Cloudflare Workers AI | 384 | 512 | 10K neurons/day (shared) |
BGE Base EN v1.5 (CF)@cf/baai/bge-base-en-v1.5 | Cloudflare Workers AI | 768 | 512 | 10K neurons/day (shared) |
BGE Large EN v1.5 (CF)@cf/baai/bge-large-en-v1.5 | Cloudflare Workers AI | 1024 | 512 | 10K neurons/day (shared) |
Mistral Embedmistral-embed | Mistral | 1024 | 8192 | free mode · monthly cap (shared) |
Codestral Embedcodestral-embed | Mistral | 1536 | 8192 | free mode · monthly cap (shared) |
Llama Text Embed v2 (Pinecone)llama-text-embed-v2 | Pinecone | 1024 | 2048 | 5M tokens/mo per model |
Multilingual E5 Large (Pinecone)multilingual-e5-large | Pinecone | 1024 | 507 | 5M tokens/mo per model |
Nemotron 3 Embed 1B (Speka)nvidia/nemotron-3-embed-1b | Speka | 2048 | 8192 | $1/month shared across Speka models |
OpenAI: Text Embedding 3 Small (ElectronHub)text-embedding-3-small | ElectronHub | 1536 | 8192 | $0.25/week shared free credits |
OpenAI: Text Embedding 3 Large (ElectronHub)text-embedding-3-large | ElectronHub | 3072 | 8192 | $0.25/week shared free credits |
Nemotron 3 Embed 8B (Inferbase)nvidia-nemotron-3-embed-8b | Inferbase | 4096 | 8192 | 5,000 requests/month; 100 requests and $0.50 usage/day shared |
Qwen 3 Embedding 0.6B (Inferbase)qwen3-embedding-0-6b | Inferbase | 1024 | 8192 | 5,000 requests/month; 100 requests and $0.50 usage/day shared |
Qwen 3 Embedding 4B (Inferbase)qwen3-embedding-4b | Inferbase | 2560 | 8192 | 5,000 requests/month; 100 requests and $0.50 usage/day shared |
Qwen 3 Embedding 8B (Inferbase)qwen3-embedding-8b | Inferbase | 4096 | 8192 | 5,000 requests/month; 100 requests and $0.50 usage/day shared |
LFM2.5 Embedding 350M (LLMTR)liquid/lfm-2.5-embedding-350m-free | LLMTR | 1024 | 512 | Ongoing zero-price route; provider terms apply |
BGE-M3 (SEA-LION)BAAI/bge-m3 | SEA-LION | 1024 | 8192 | free · 10 rpm |
Cohere Embed English v3embed-english-v3.0 | Cohere | 1024 | 512 | 1K calls/mo (shared w/ chat) |
Qwen3 Embedding 8B (OVH)Qwen3-Embedding-8B | OVH AI Endpoints | 4096 | 32768 | free · anonymous 2 req/min per IP |
BGE-M3 (OVH)bge-m3 | OVH AI Endpoints | 1024 | 8192 | free · anonymous 2 req/min per IP |
BGE Multilingual Gemma2 (OVH)bge-multilingual-gemma2 | OVH AI Endpoints | 3584 | 8192 | free · anonymous 2 req/min per IP |
Mistral: Codestral Embed (ElectronHub)codestral-embed | ElectronHub | 1536 | 8192 | $0.25/week shared free credits |
Mistral: Mistral Embed (ElectronHub)mistral-embed | ElectronHub | 1024 | 8192 | $0.25/week shared free credits |
Google: Gemini Embedding 2 (ElectronHub)gemini-embedding-2 | ElectronHub | 3072 | 8192 | $0.25/week shared free credits |
Google: Gemini Embedding 001 (ElectronHub)gemini-embedding-001 | ElectronHub | 3072 | 2048 | $0.25/week shared free credits |
OpenAI: Text Embedding Ada 002 (ElectronHub)text-embedding-ada-002 | ElectronHub | 1536 | 8192 | $0.25/week shared free credits |
Cohere Embed English Light v3embed-english-light-v3.0 | Cohere | 384 | 512 | 1K calls/mo (shared w/ chat) |
Cohere Embed Multilingual v3embed-multilingual-v3.0 | Cohere | 1024 | 512 | 1K calls/mo (shared w/ chat) |
Cohere Embed Multilingual Light v3embed-multilingual-light-v3.0 | Cohere | 384 | 512 | 1K calls/mo (shared w/ chat) |
ข้อมูลสดจากแคตตาล็อก FreeLLMAPI (เวอร์ชัน 2026.11.19 ตรวจสอบเมื่อ 2026-11-19) ขีดจำกัดฟรีเปลี่ยนบ่อย แคตตาล็อกถูกตรวจสอบทุกวัน
- ผู้ให้บริการหลายรายสำหรับตระกูลเดียว: ตระกูลเช่น
bge-m3ฟรีบนผู้ให้บริการมากกว่าหนึ่งราย การสลับสำรองจึงมีที่ไป - อินพุตสูงสุด: chunk ที่ยาวกว่าอินพุตสูงสุดจะถูกตัดหรือถูกปฏิเสธ ทำให้ chunk เล็กกว่าค่านี้
- ภาษา: สำหรับข้อความที่ไม่ใช่ภาษาอังกฤษ ให้ใช้ตระกูลหลายภาษาเช่น
bge-m3ตระกูลที่มี-en-ในชื่อใช้สำหรับภาษาอังกฤษ - มิติ: เวกเตอร์ที่ใหญ่กว่าใช้พื้นที่เก็บข้อมูลมากกว่า สำหรับดัชนีขนาดเล็ก เรื่องนี้ไม่เป็นปัญหา
โค้ด RAG ครบชุดด้วย Python
สคริปต์แบ่งไฟล์ข้อความเป็น chunk, embed เป็นชุด และบันทึกเวกเตอร์ด้วย NumPy จากนั้นตอบคำถามด้วย chunk ที่ตรงที่สุด และแสดงแหล่งที่มา สคริปต์ลองใหม่เมื่อขีดจำกัดหยุดคำขอ
rag.py
import json
import os
import pathlib
import time
import numpy as np
import openai
from openai import OpenAI
client = OpenAI(
base_url="http://localhost:3001/v1",
api_key=os.environ["FREELLMAPI_API_KEY"],
max_retries=3,
timeout=90,
)
EMBED_MODEL = "bge-m3" # keep one family for the whole index
CHAT_MODEL = "auto" # or a long-context profile: auto:<profile>
INDEX = pathlib.Path("index")
def with_retry(fn, *args, **kwargs):
for attempt in range(6):
try:
return fn(*args, **kwargs)
except openai.RateLimitError as err:
header = err.response.headers.get("retry-after", "")
time.sleep(min(int(header) if header.isdigit() else 2 ** attempt, 120))
raise RuntimeError("Rate limited on every provider")
def chunk(text: str, size: int = 1500, overlap: int = 200) -> list[str]:
step = size - overlap
return [text[i:i + size] for i in range(0, max(len(text), 1), step)]
def embed(texts: list[str], batch: int = 32) -> np.ndarray:
out = []
for i in range(0, len(texts), batch):
resp = with_retry(client.embeddings.create, model=EMBED_MODEL, input=texts[i:i + batch])
out.extend(d.embedding for d in resp.data)
vecs = np.array(out, dtype=np.float32)
return vecs / np.linalg.norm(vecs, axis=1, keepdims=True)
def build(folder: str) -> None:
chunks = []
for path in sorted(pathlib.Path(folder).rglob("*.md")):
for part in chunk(path.read_text(encoding="utf-8")):
if part.strip():
chunks.append({"source": str(path), "text": part})
INDEX.mkdir(exist_ok=True)
np.save(INDEX / "vectors.npy", embed([c["text"] for c in chunks]))
(INDEX / "chunks.json").write_text(json.dumps(chunks))
def answer(question: str, k: int = 5) -> str:
vecs = np.load(INDEX / "vectors.npy")
chunks = json.loads((INDEX / "chunks.json").read_text())
q = embed([question])[0]
top = np.argsort(vecs @ q)[::-1][:k]
context = "\n\n".join(f"[{n + 1}] ({chunks[i]['source']})\n{chunks[i]['text']}" for n, i in enumerate(top))
resp = with_retry(
client.chat.completions.create,
model=CHAT_MODEL,
temperature=0,
messages=[
{"role": "system", "content": "Answer only from the sources. Cite them as [1], [2]. If the sources do not answer, say so."},
{"role": "user", "content": f"Sources:\n{context}\n\nQuestion: {question}"},
],
)
return resp.choices[0].message.content
if __name__ == "__main__":
if not (INDEX / "vectors.npy").exists():
build("docs")
print(answer("How do I rotate the API keys?"))สำหรับมากกว่าไม่กี่พัน chunk ให้แทนที่การค้นหาด้วย NumPy ด้วยฐานข้อมูลเวกเตอร์ การเรียก embedding และแชตยังคงเหมือนเดิม
ผู้ใช้มักถามคำถามเดิมซ้ำ FreeLLMAPI มี response cache แบบเลือกเปิดสำหรับคำขอที่เหมือนกัน การตอบจาก cache ไม่ใช้โควตาของผู้ให้บริการ คุณเปิดหรือปิด cache ให้คำขอเดียวได้ด้วย header X-FreeLLM-Cache: on หรือ off ใช้ temperature=0 เพื่อให้คำถามเดียวกันสร้างคำขอเดียวกัน
เพิ่มขั้นตอน rerank
การค้นหาเวกเตอร์พบข้อความที่คล้ายกัน แต่ chunk อันดับแรกไม่ใช่คำตอบที่ดีที่สุดเสมอไป ขั้นตอน rerank จัดเรียงตัวเลือกใหม่ เอกสาร FreeLLMAPI ไม่ได้อธิบาย endpoint rerank โดยเฉพาะ คุณใช้โมเดลแชตที่เร็วเป็น reranker ได้ ดึงตัวเลือก 15 รายการและเก็บ 5 รายการที่ดีที่สุด
LLM rerank ด้วย auto:fast
def rerank(question: str, candidates: list[str], keep: int = 5) -> list[int]:
listing = "\n".join(f"{n}: {c[:400]}" for n, c in enumerate(candidates))
resp = with_retry(
client.chat.completions.create,
model="auto:fast",
temperature=0,
messages=[{
"role": "user",
"content": (
f"Question: {question}\n\nPassages:\n{listing}\n\n"
f"Return the numbers of the {keep} most useful passages, best first, "
"as a JSON list of integers. Return only the list."
),
}],
)
try:
ids = json.loads(resp.choices[0].message.content.strip())
return [i for i in ids if isinstance(i, int) and 0 <= i < len(candidates)][:keep]
except (json.JSONDecodeError, AttributeError):
return list(range(min(keep, len(candidates)))) # fall back to vector order
# Use it in answer(): take 15 candidates, keep the best 5
# top = np.argsort(vecs @ q)[::-1][:15]
# best = rerank(question, [chunks[i]["text"] for i in top])
# top = [top[i] for i in best]ขั้นตอน rerank เพิ่มหนึ่งคำขอแชตต่อคำถาม หากขีดจำกัดฟรีของคุณตึง ให้ข้ามขั้นตอนนี้ การแบ่ง chunk ที่ดีกว่ามักช่วยได้มากกว่าขั้นตอน rerank
Long context: เมื่อไม่ต้องใช้การค้นคืน
ปัจจุบัน ข้อเสนอโมเดลฟรี 56 รายการมีหน้าต่าง context ตั้งแต่ 1 ล้านโทเค็นขึ้นไป หากเอกสารของคุณมีขนาดเล็ก คุณส่งทั้งหมดในพรอมต์และข้ามดัชนีเวกเตอร์ได้ วิธีนี้ง่ายกว่า แต่แต่ละคำถามจะส่งโทเค็นจำนวนมาก
| โมเดล | ฟรีบน | ขนาดบริบท | ขีดจำกัดฟรี (ข้อเสนอที่ดีที่สุด) | เครื่องมือ | การอ่านภาพ |
|---|---|---|---|---|---|
| OpenAI: GPT-6 Luna | ElectronHub | 1.1M | $0.25/week shared free credits | ไม่ | ไม่ |
| Gemini 3.8 Flash | APINex, Google AI Studio | 1M | 5 คำขอ/นาที 10M weighted tokens/day shared across APINex free routes; 3x token multiplier; 5 requests/minute/account | ใช่ | ใช่ |
| Gemini 3.7 Flash | Google AI Studio | 1M | 10 คำขอ/นาที 20 คำขอ/วัน 250,000 โทเคน/นาที ~3M | ใช่ | ใช่ |
| DeepSeek V4 Flash | AMD Radeon Cloud, BazaarLink, ElectronHub | 1M | 10 คำขอ/นาที 50 คำขอ/วัน Shared rate limit | ใช่ | ไม่ |
| DeepSeek V4 Flash 0731 | ElectronHub, Router9 | 1M | 10,000 credits/month (~$1), shared; account-anniversary reset | ไม่ | ไม่ |
| Gemini 3.6 Flash | Google AI Studio | 1M | 10 คำขอ/นาที 20 คำขอ/วัน 250,000 โทเคน/นาที ~3M | ใช่ | ใช่ |
| GLM 5.2 | Router9 | 1M | 10,000 credits/month (~$1), shared; account-anniversary reset | ไม่ | ไม่ |
| Gemini 3.5 Flash | Google AI Studio | 1M | 10 คำขอ/นาที 20 คำขอ/วัน 250,000 โทเคน/นาที ~3M | ใช่ | ใช่ |
| DeepSeek V4 Pro | APINex, Router9 | 1M | 5 คำขอ/นาที 10M weighted tokens/day shared across APINex free routes; 3x token multiplier; 5 requests/minute/account | ไม่ | ไม่ |
| Nemotron 3 Ultra 550B | Gizmo, Kilo Gateway, LLMTR +3 รายการเพิ่มเติม | 1M | 200 คำขอ/วัน 200 rpd | ใช่ | ไม่ |
แสดง 10 จาก 35 โมเดลฟรีที่ตรงกัน ดูโมเดลทั้งหมด.
ข้อมูลสดจากแคตตาล็อก FreeLLMAPI (เวอร์ชัน 2026.11.19 ตรวจสอบเมื่อ 2026-11-19) ขีดจำกัดฟรีเปลี่ยนบ่อย แคตตาล็อกถูกตรวจสอบทุกวัน
- ใช้ long context สำหรับเอกสารไม่กี่ฉบับ คำถามที่ต้องใช้ข้อความทั้งหมด หรือรายงานฉบับเดียว
- ใช้การค้นคืน สำหรับเอกสารจำนวนมาก คำถามที่ถามบ่อย หรือเมื่อขีดจำกัดโทเค็นต่อนาทีฟรีต่ำ
- รวมทั้งสองวิธี: ค้นคืน chunk 20 รายการขึ้นไปแล้วส่งไปยังโมเดล long context
พรอมต์ขนาดใหญ่อาจล้มเหลวบนผู้ให้บริการที่มีขีดจำกัดโทเค็นต่อนาทีต่ำ FreeLLMAPI จะลองผู้ให้บริการรายถัดไป หากต้องการควบคุมว่าโมเดลใดรับพรอมต์ขนาดใหญ่ ให้สร้างโปรไฟล์เชนสำรองที่มีเฉพาะโมเดล long context ใช้เป็น auto:<profile>
ขีดจำกัดและการแก้ไขปัญหา
| ปัญหา | สาเหตุ | วิธีแก้ |
|---|---|---|
| การนำเข้าข้อมูลหยุดด้วย 429 | ตระกูล embedding ถึงขีดจำกัดบนทุกผู้ให้บริการ | ใช้ชุดที่ใหญ่ขึ้น รอตาม Retry-After นำเข้าข้อมูลเป็นส่วนๆ |
| ผลลัพธ์แย่ลงหลังการเปลี่ยนแปลง | ดัชนีมีเวกเตอร์จากสองตระกูล | embed ทุก chunk ใหม่ด้วยตระกูลเดียว |
| ข้อผิดพลาดเกี่ยวกับความยาวอินพุต | chunk ยาวกว่าอินพุตสูงสุดของตระกูล | ใช้ chunk ที่เล็กลง |
| คำตอบไม่สนใจแหล่งที่มา | โมเดลตอบจากความรู้ของตนเอง | ใช้ temperature=0 และ system prompt ที่เข้มงวด |
| ข้อผิดพลาดความยาว context ตอนสร้างคำตอบ | chunk มากเกินไปหรือยาวเกินไป | ลดค่า k หรือใช้โปรไฟล์ long context |
| สไตล์ของคำตอบเปลี่ยน | เราเตอร์เลือกโมเดลอื่น | ส่ง header X-Session-Id หรือกำหนดโมเดล |
แพ็กเกจฟรีไม่มี SLA โมเดลที่แข็งแรงที่สุดถึงขีดจำกัดรายวันก่อน และขีดจำกัดหลายรายการรีเซ็ตเที่ยงคืน UTC ทดสอบไปป์ไลน์ของคุณด้วยโมเดลที่เชนของคุณจะใช้งานจริง
คำถามที่พบบ่อย
มี API ฟรีสำหรับ RAG หรือไม่
มี ผู้ให้บริการหลายรายมีแพ็กเกจฟรีสำหรับ embedding และแชต FreeLLMAPI ให้บริการทั้งสองผ่านคีย์ OpenAI-compatible เพียงคีย์เดียว พร้อมการสลับสำรองระหว่างผู้ให้บริการ
โมเดล embedding ฟรีตัวไหนดีที่สุดสำหรับ RAG
เลือกตระกูลที่ฟรีบนผู้ให้บริการหลายรายและเหมาะกับภาษาของคุณ สำหรับข้อความหลายภาษา bge-m3 เป็นตัวเลือกที่พบบ่อย ใช้ตระกูลเดียวตลอดทั้งดัชนี
มี rerank API ฟรีหรือไม่
เอกสาร FreeLLMAPI ไม่ได้อธิบาย endpoint rerank คุณทำ rerank ด้วยโมเดลแชตที่เร็วได้ ตามที่แสดงในหน้านี้ หรือข้ามขั้นตอน rerank ก็ได้
ฉันต้องใช้ RAG หรือไม่ หากโมเดลฟรีมี context 1 ล้านโทเค็น
ไม่จำเป็นสำหรับเอกสารขนาดเล็กไม่กี่ฉบับ สำหรับเอกสารจำนวนมากหรือคำถามที่ถามบ่อย การค้นคืนส่งโทเค็นน้อยลงต่อคำขอและอยู่ในขีดจำกัดฟรี
ฉันเปลี่ยนโมเดล embedding ภายหลังได้หรือไม่
ได้ แต่คุณต้อง embed ทุก chunk ใหม่ เวกเตอร์จากสองโมเดลไม่เข้ากัน จึงไม่ควรผสมในดัชนีเดียวกัน
คู่มือที่เกี่ยวข้อง
- Embeddings API ฟรี
- Free LLM API ที่มี context 1 ล้านโทเค็น
- LLM ฟรีสำหรับ LlamaIndex
- Free LLM API สำหรับ LangChain
- LLM API ฟรีใน Python
แหล่งข้อมูล
- FreeLLMAPI docs: embeddings (families and failover rules) (ตรวจสอบเมื่อ 20 November 2026)
- FreeLLMAPI docs: routing strategies and response headers (ตรวจสอบเมื่อ 20 November 2026)
- OpenAI Python SDK: embeddings, errors and retries (ตรวจสอบเมื่อ 20 November 2026)