Free LLM API สำหรับ LangChain
LangChain เชื่อมกับ API ที่เข้ากันได้กับ OpenAI ผ่าน ChatOpenAI และ OpenAIEmbeddings คุณเปลี่ยนเพียง base URL และคีย์ คู่มือนี้ชี้ทั้งสองคลาสไปยัง FreeLLMAPI ซึ่งรวมระดับฟรีของผู้ให้บริการ 45 ราย ไว้หลังคีย์เดียว โค้ดด้านล่างทำงานได้ทั้งใน Python และ JavaScript และจัดการขีดจำกัดอัตราให้
โค้ด ชื่อโมเดล และป้ายกำกับของแคตตาล็อกสดจะแสดงเป็นภาษาอังกฤษ
ตั้งค่าเกตเวย์และแพ็กเกจ
ติดตั้ง FreeLLMAPI และเพิ่มคีย์ฟรีจากผู้ให้บริการอย่างน้อยสองรายในหน้า Keys ของแดชบอร์ด คัดลอกคีย์รวม โค้ดของคุณใช้เพียงคีย์นี้ คีย์ของผู้ให้บริการยังคงอยู่ใน FreeLLMAPI
ติดตั้ง FreeLLMAPI และแพ็กเกจ LangChain
curl -fsSL https://freellmapi.co/install.sh | bash
# Python
pip install -U langchain langchain-openai
# JavaScript
npm install @langchain/openai @langchain/core zodตัวแปรสภาพแวดล้อม
export FREELLMAPI_BASE_URL=http://localhost:3001/v1
export FREELLMAPI_API_KEY=<unified-key>ใช้ model="auto" เพื่อให้เราเตอร์เลือกโมเดล คุณใช้กลยุทธ์การกำหนดเส้นทางได้ด้วย เช่น auto:fast หรือ auto:smart โปรไฟล์ที่มีชื่อ เช่น auto:coding และ ID โมเดลคงที่จากแคตตาล็อกก็ใช้ได้เช่นกัน
หากต้องการดูว่าคีย์ของคุณเรียกโมเดลใดได้ตอนนี้ ให้ร้องขอ GET /v1/models?execution_status=ready รายการเต็มยังมีโมเดลที่ไม่มีคีย์ด้วย โมเดลที่มีสถานะ exhausted มีคีย์ แต่ทุกคีย์ถึงขีดจำกัดในขณะนี้ สถานะนี้จะหายไปเมื่อช่วงพักสิ้นสุด
แสดงรายการโมเดลที่ตอบได้ตอนนี้
curl "http://localhost:3001/v1/models?execution_status=ready" \
-H "Authorization: Bearer <unified-key>"แชตด้วย ChatOpenAI
ใน Python ตั้งค่า base_url และ api_key ค่า max_retries จะถูกส่งไปยังไคลเอนต์ OpenAI ซึ่งลองใหม่เมื่อเกิดข้อผิดพลาด 429 และ 5xx โดยรอแบบเพิ่มขึ้นเป็นทวีคูณ
Python: แชตและสตรีมมิง
import os
from langchain_openai import ChatOpenAI
llm = ChatOpenAI(
model="auto",
base_url=os.environ["FREELLMAPI_BASE_URL"],
api_key=os.environ["FREELLMAPI_API_KEY"],
temperature=0.2,
max_retries=3,
timeout=60,
include_response_headers=True,
)
msg = llm.invoke("Explain retrieval-augmented generation in two sentences.")
print(msg.content)
print("Served by:", msg.response_metadata["headers"].get("x-routed-via"))
for chunk in llm.stream("Write a haiku about SQLite."):
print(chunk.content, end="", flush=True)ใน JavaScript ใส่ base URL ใน configuration.baseURL ออบเจ็กต์ configuration จะถูกส่งไปยังไคลเอนต์ SDK ของ OpenAI อย่างเป็นทางการ
JavaScript: แชตและสตรีมมิง
import { ChatOpenAI } from "@langchain/openai";
const llm = new ChatOpenAI({
model: "auto",
apiKey: process.env.FREELLMAPI_API_KEY,
temperature: 0.2,
maxRetries: 3,
configuration: { baseURL: process.env.FREELLMAPI_BASE_URL },
});
const msg = await llm.invoke("Explain retrieval-augmented generation in two sentences.");
console.log(msg.content);
for await (const chunk of await llm.stream("Write a haiku about SQLite.")) {
process.stdout.write(String(chunk.content));
}header x-routed-via แสดงผู้ให้บริการและโมเดลที่ตอบ หากเราเตอร์เปลี่ยนผู้ให้บริการ x-fallback-trail จะแสดงความพยายามที่ล้มเหลวแต่ละครั้งและเหตุผล
เครื่องมือและเอเจนต์
FreeLLMAPI ส่ง tools แบบ OpenAI ไปยังแต่ละผู้ให้บริการ และส่ง tool_calls กลับในรูปแบบ OpenAI สำหรับ Gemini ระบบแปลงคำขอเป็นรูปแบบของ Google และแปลงกลับ ใช้ bind_tools สำหรับการเรียกหนึ่งครั้ง หรือ create_agent สำหรับลูปที่รันเครื่องมือ
Python: bind_tools และ create_agent
from langchain.agents import create_agent
from langchain_core.tools import tool
@tool
def get_weather(city: str) -> str:
"""Return the current weather for a city."""
return f"It is 18 C and cloudy in {city}."
# One call: the model returns the tool call, your code runs it
msg = llm.bind_tools([get_weather]).invoke("What is the weather in Dublin?")
print(msg.tool_calls)
# Agent loop: LangChain runs the tool and sends the result back
agent = create_agent(
model=llm,
tools=[get_weather],
system_prompt="You answer weather questions. Use the tool.",
)
result = agent.invoke({"messages": [{"role": "user", "content": "Weather in Dublin?"}]})
print(result["messages"][-1].content)JavaScript: bindTools
import { tool } from "@langchain/core/tools";
import { z } from "zod";
const getWeather = tool(
async ({ city }) => `It is 18 C and cloudy in ${city}.`,
{
name: "get_weather",
description: "Return the current weather for a city.",
schema: z.object({ city: z.string() }),
},
);
const reply = await llm.bindTools([getWeather]).invoke("What is the weather in Dublin?");
console.log(reply.tool_calls);มีเพียงบางโมเดลฟรีที่รองรับการเรียกใช้เครื่องมือ เมื่อใช้ auto ให้เก็บโมเดลที่เรียกใช้เครื่องมือได้ไว้ในห่วงโซ่สำรอง หรือสร้างโปรไฟล์สำหรับเอเจนต์ โมเดลฟรีเหล่านี้รองรับเครื่องมือในขณะนี้:
| โมเดล | ฟรีบน | ขนาดบริบท | ขีดจำกัดฟรี (ข้อเสนอที่ดีที่สุด) | เครื่องมือ | การอ่านภาพ |
|---|---|---|---|---|---|
| GLM 5.3 | UnoRouter | 1M | 1 คำขอ/นาที 1 req/min per model | ใช่ | ไม่ |
| GLM 5.3 Flash | NVIDIA NIM, UnoRouter | 1M | 40 คำขอ/นาที 40 RPM | ใช่ | ใช่ |
| Gemini 3.8 Flash | Google AI Studio | 1M | Recurring provider quota | ใช่ | ใช่ |
| Qwen3.8 Flash Next | AMD Radeon Cloud | 262K | Recurring daily account allowance | ใช่ | ไม่ |
| Qwen3.8 Flash | ElectronHub | 1M | $0.25/week shared recurring credit | ใช่ | ใช่ |
| Gemini 3.7 Flash | Google AI Studio | 1M | 10 คำขอ/นาที 20 คำขอ/วัน 250,000 โทเคน/นาที ~3M | ใช่ | ใช่ |
| GPT-5.6 Luna | ElectronHub | 1M | $0.25/week shared recurring credit | ใช่ | ใช่ |
| Dots3 Note Preview | Kilo Gateway, OpenRouter | 512K | 20 คำขอ/นาที 50 คำขอ/วัน 50 req/day account-wide (1,000 after a $10 purchase) | ใช่ | ใช่ |
| DeepSeek V4 Flash | AMD Radeon Cloud, BazaarLink, ElectronHub | 1M | 10 คำขอ/นาที 50 คำขอ/วัน Shared rate limit | ใช่ | ไม่ |
| Qwen3.8 27B | ElectronHub, Groq, OVH AI Endpoints | 262K | 30 คำขอ/นาที 250 คำขอ/วัน 70,000 โทเคน/นาที ~6M | ใช่ | ใช่ |
แสดง 10 จาก 109 โมเดลฟรีที่ตรงกัน ดูโมเดลทั้งหมด.
ข้อมูลสดจากแคตตาล็อก FreeLLMAPI (เวอร์ชัน 2026.11.19 ตรวจสอบเมื่อ 2026-11-19) ขีดจำกัดฟรีเปลี่ยนบ่อย แคตตาล็อกถูกตรวจสอบทุกวัน
Embedding ด้วย OpenAIEmbeddings
โดยค่าเริ่มต้น OpenAIEmbeddings ใน Python แบ่งข้อความด้วย tokenizer ของ OpenAI และส่งเป็นโทเคน ผู้ให้บริการอื่นส่วนใหญ่ต้องการข้อความดิบ ตั้งค่า check_embedding_ctx_length=False เพื่อส่งข้อความ
Python: embedding
from langchain_openai import OpenAIEmbeddings
emb = OpenAIEmbeddings(
model="bge-m3", # one embedding family, 1024 dimensions
base_url=os.environ["FREELLMAPI_BASE_URL"],
api_key=os.environ["FREELLMAPI_API_KEY"],
check_embedding_ctx_length=False,
)
vectors = emb.embed_documents(["FreeLLMAPI pools free tiers.", "LangChain builds LLM apps."])
print(len(vectors), len(vectors[0]))JavaScript: embedding
import { OpenAIEmbeddings } from "@langchain/openai";
const emb = new OpenAIEmbeddings({
model: "bge-m3",
apiKey: process.env.FREELLMAPI_API_KEY,
configuration: { baseURL: process.env.FREELLMAPI_BASE_URL },
});
const vector = await emb.embedQuery("What does FreeLLMAPI do?");
console.log(vector.length);การสลับ 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) ขีดจำกัดฟรีเปลี่ยนบ่อย แคตตาล็อกถูกตรวจสอบทุกวัน
เอาต์พุตที่มีโครงสร้าง เซสชัน และการเลือกโมเดล
with_structured_output คืนค่าเป็นออบเจ็กต์ Pydantic แทนข้อความ โดยค่าเริ่มต้น LangChain ใช้การเรียกฟังก์ชันสำหรับสิ่งนี้ วิธีนี้ใช้ได้กับทุกโมเดลฟรีที่รองรับเครื่องมือ
Python: เอาต์พุตที่มีโครงสร้าง
from pydantic import BaseModel, Field
class Ticket(BaseModel):
category: str = Field(description="billing, bug or other")
urgent: bool
classifier = llm.with_structured_output(Ticket)
ticket = classifier.invoke("The app crashes when I pay. Please fix it today.")
print(ticket.category, ticket.urgent)อย่าใช้ method="json_schema" กับ auto ผู้ให้บริการฟรีไม่ได้รองรับเอาต์พุต JSON schema แบบเข้มงวดทุกราย และเราเตอร์อาจเลือกผู้ให้บริการต่างกันในแต่ละคำขอ
FreeLLMAPI เก็บการสนทนาไว้กับโมเดลเดียวนาน 30 นาที ระบบหาการสนทนาจาก header X-Session-Id หากไม่มี header ระบบจะใช้แฮชของข้อความผู้ใช้แรก สำหรับแอปแชตที่มีผู้ใช้จำนวนมาก ให้ส่ง session ID หนึ่งรายการต่อผู้ใช้หนึ่งคน:
Python: หนึ่งเซสชันต่อผู้ใช้
def llm_for(user_id: str) -> ChatOpenAI:
return ChatOpenAI(
model="auto",
base_url=os.environ["FREELLMAPI_BASE_URL"],
api_key=os.environ["FREELLMAPI_API_KEY"],
default_headers={"X-Session-Id": f"user-{user_id}"},
max_retries=3,
)เลือกสตริงโมเดลสำหรับแต่ละส่วนของแอปของคุณ:
| งานในแอปของคุณ | สตริงโมเดล | เหตุผล |
|---|---|---|
| คำตอบแชตสำหรับผู้ใช้ | auto | ทำตามห่วงโซ่ที่คุณตั้งไว้ในแดชบอร์ด |
| เอเจนต์ที่ใช้เครื่องมือ | auto:<profile> | โปรไฟล์ที่มีเฉพาะโมเดลที่เรียกใช้เครื่องมือได้ |
| การจัดประเภท การกำหนดเส้นทาง และการสรุปสั้น | auto:fast | จัดอันดับโมเดลตามความเร็วที่วัดได้ |
| ขั้นตอนการให้เหตุผลที่ยาก | auto:smart | จัดอันดับโมเดลตามความฉลาด |
| การทดสอบที่ต้องทำซ้ำได้ | ID โมเดลคงที่ | โมเดลเดิมทุกครั้ง แต่จะหยุดเมื่อถึงขีดจำกัดของโมเดลนั้น |
ระดับฟรีไม่มี SLA เวลาแฝงเปลี่ยนไปตลอดวัน และโมเดลที่แข็งแรงที่สุดจะถึงขีดจำกัดรายวันก่อน ทดสอบห่วงโซ่ของคุณด้วยโมเดลที่ห่วงโซ่จะใช้จริง
ขีดจำกัดอัตราและการลองใหม่
FreeLLMAPI ลองผู้ให้บริการรายถัดไปเมื่อรายหนึ่งส่ง 429 โค้ดของคุณจะเห็น 429 ก็ต่อเมื่อทุกคีย์ในห่วงโซ่ถึงขีดจำกัด จากนั้นการตอบกลับจะมี header Retry-After ขีดจำกัดรายวันหลายรายการรีเซ็ตเที่ยงคืนตามเวลา UTC
สำหรับงานแบบชุด ให้เพิ่มชั้นการลองใหม่ที่สองด้วย with_retry ระบบจะลองทั้ง runnable ใหม่ด้วยการรอแบบเพิ่มขึ้นเป็นทวีคูณและ jitter
Python: ลองห่วงโซ่ใหม่เมื่อเจอขีดจำกัดอัตรา
import openai
from langchain_core.prompts import ChatPromptTemplate
prompt = ChatPromptTemplate.from_messages([
("system", "Summarize the text in one sentence."),
("user", "{text}"),
])
chain = (prompt | llm).with_retry(
retry_if_exception_type=(openai.RateLimitError, openai.APITimeoutError),
wait_exponential_jitter=True,
stop_after_attempt=5,
)
# batch() runs requests in parallel; max_concurrency keeps the rate low
results = chain.batch(
[{"text": t} for t in ["First document.", "Second document."]],
config={"max_concurrency": 4},
)| ปัญหา | สาเหตุ | วิธีแก้ |
|---|---|---|
openai.AuthenticationError | คีย์รวมผิด | คัดลอกคีย์อีกครั้งจากหน้า Keys |
openai.NotFoundError ทุกครั้งที่เรียก | base URL ไม่มี /v1 | ใช้ http://localhost:3001/v1 |
openai.RateLimitError | ทุกคีย์ในห่วงโซ่ถึงขีดจำกัดแล้ว | เพิ่มผู้ให้บริการ ลด max_concurrency หรือรอ Retry-After |
| Embedding ผิดพลาดเกี่ยวกับโทเคนหรือชนิดอินพุต | LangChain ส่งโทเคน ไม่ใช่ข้อความ | ตั้งค่า check_embedding_ctx_length=False |
tool_calls ว่างเปล่า | โมเดลไม่รองรับเครื่องมือ | ใช้โมเดลจากตารางเครื่องมือ หรือโปรไฟล์สำหรับเครื่องมือ |
| ไม่มีข้อความการให้เหตุผล | ChatOpenAI เก็บเฉพาะฟิลด์มาตรฐานของ OpenAI | อ่านคำตอบใน content ฟิลด์เพิ่มเติมของผู้ให้บริการจะไม่ถูกเก็บ |
คำถามที่พบบ่อย
ฉันใช้ Free LLM API กับ LangChain ได้ไหม
ได้ API ใดก็ได้ที่เข้ากันได้กับ OpenAI ใช้กับ ChatOpenAI ได้ ตั้ง base_url เป็น http://localhost:3001/v1 และ api_key เป็นคีย์รวม FreeLLMAPI ของคุณ เราเตอร์ใช้ระดับฟรีของผู้ให้บริการ
ฉันตั้ง base URL ที่กำหนดเองใน ChatOpenAI ของ LangChain อย่างไร
ใน Python ส่ง base_url ให้ ChatOpenAI ใน JavaScript ส่ง configuration: { baseURL } ให้ constructor ตัวแปรสภาพแวดล้อม OPENAI_BASE_URL ก็ใช้ได้ใน Python เช่นกัน
เอเจนต์ของ LangChain ใช้งานกับโมเดลฟรีได้ไหม
ได้ หากโมเดลรองรับการเรียกใช้เครื่องมือ ใช้ create_agent กับโมเดล ChatOpenAI และเก็บโมเดลที่เรียกใช้เครื่องมือได้ไว้ในห่วงโซ่ FreeLLMAPI ของคุณ
ทำไม OpenAIEmbeddings ล้มเหลวกับผู้ให้บริการที่ไม่ใช่ OpenAI
โดยค่าเริ่มต้นระบบส่ง ID ของโทเคน ผู้ให้บริการอื่นส่วนใหญ่ต้องการข้อความดิบ ตั้ง check_embedding_ctx_length=False ใน Python
ฉันจัดการข้อผิดพลาด 429 ใน LangChain อย่างไร
ตั้ง max_retries บน ChatOpenAI และเพิ่ม with_retry ให้ห่วงโซ่สำหรับงานแบบชุด FreeLLMAPI ย้ายไปผู้ให้บริการรายถัดไปก่อนที่โค้ดของคุณจะเห็น 429 อยู่แล้ว
คู่มือที่เกี่ยวข้อง
- LLM ฟรีสำหรับ LlamaIndex
- LLM API ฟรีใน Python
- Free LLM API สำหรับ RAG
- Embeddings API ฟรี
- Free LLM API ที่รองรับ function calling
- Free LLM API สำหรับ AI agent
แหล่งข้อมูล
- LangChain docs: ChatOpenAI integration (Python) (ตรวจสอบเมื่อ 20 November 2026)
- LangChain docs: ChatOpenAI integration (JavaScript) (ตรวจสอบเมื่อ 20 November 2026)
- LangChain docs: agents and create_agent (ตรวจสอบเมื่อ 20 November 2026)
- LangChain source: OpenAIEmbeddings note on OpenAI-compatible APIs (ตรวจสอบเมื่อ 20 November 2026)
- OpenAI Python SDK: retries and errors (ตรวจสอบเมื่อ 20 November 2026)
- FreeLLMAPI docs: REST API (tool calling, embeddings, response headers) (ตรวจสอบเมื่อ 20 November 2026)