BazaarLinkBazaarLink
Sign in
← 所有文章
2026-05-01 · LangChain · free LLM API · auto:free · OpenAI compatible API · developer guide

LangChain Free LLM API Setup — auto:free Routing Guide (2026)

Set up LangChain with a genuinely free LLM API in 3 steps. BazaarLink auto:free routes to zero-cost models automatically — no credit card, no trial expiry. Works with ChatOpenAI, LCEL, and tool-calling agents.

LangChain works with any OpenAI-compatible API — you just set openai_api_base (Python) or baseURL (TypeScript) and you're done. The hard part is finding a free API that doesn't expire, doesn't need a credit card, and works reliably enough for development.

BazaarLink's auto:free model ID solves this cleanly: it automatically routes your request to whichever capable free model is available, so you don't have to track which specific models are free this week. You write one model string and it stays valid.

Note: Free tier: 10 requests/min · 150 requests/day · no credit card · no trial expiry. The auto:free routing continues working indefinitely — it's not a trial that disappears after 30 days.

Quickstart — 3 Steps

Step 1: Get a free API key

Sign up at bazaarlink.ai/free and create a key under Keys. No credit card required. The key format is sk-bl-xxxxxxxxxx.

Step 2: Install LangChain

# Python
pip install langchain langchain-openai

# TypeScript / Node
npm install langchain @langchain/openai

Change base_url to https://bazaarlink.ai/api/v1 and use auto:free as the model. Everything else stays the same.

Python — ChatOpenAI Setup

from langchain_openai import ChatOpenAI

llm = ChatOpenAI(
    model="auto:free",
    openai_api_key="sk-bl-YOUR_KEY",
    openai_api_base="https://bazaarlink.ai/api/v1",
)

response = llm.invoke("Explain LangChain in one sentence.")
print(response.content)

TypeScript — LangChain.js Setup

import { ChatOpenAI } from "@langchain/openai";

const llm = new ChatOpenAI({
  model: "auto:free",
  openAIApiKey: "sk-bl-YOUR_KEY",
  configuration: {
    baseURL: "https://bazaarlink.ai/api/v1",
  },
});

const response = await llm.invoke("Explain LangChain in one sentence.");
console.log(response.content);

LCEL Chain Example

LangChain Expression Language (LCEL) works without any changes — pipe operators, prompt templates, and output parsers all behave exactly as they do with the OpenAI API.

from langchain_openai import ChatOpenAI
from langchain_core.prompts import ChatPromptTemplate
from langchain_core.output_parsers import StrOutputParser

llm = ChatOpenAI(model="auto:free", openai_api_key="sk-bl-YOUR_KEY",
              openai_api_base="https://bazaarlink.ai/api/v1")

prompt = ChatPromptTemplate.from_template("Summarize this in one sentence: {text}")
chain = prompt | llm | StrOutputParser()

result = chain.invoke({"text": "LangChain is a framework for building LLM applications..."})
print(result)

LangChain Agent with Tools

Tool-calling agents work with auto:free as long as the underlying model supports function calling. If you need guaranteed tool-call support, switch to a specific model like openai/gpt-4o-mini or google/gemini-flash-1.5 — same key, same endpoint.

from langchain_openai import ChatOpenAI
from langchain.agents import create_tool_calling_agent, AgentExecutor
from langchain_core.tools import tool
from langchain_core.prompts import ChatPromptTemplate

@tool
def get_word_count(text: str) -> int:
    """Count words in a text."""
    return len(text.split())

# Use auto:free for prototyping; swap model for guaranteed tool support
llm = ChatOpenAI(model="auto:free", openai_api_key="sk-bl-YOUR_KEY",
              openai_api_base="https://bazaarlink.ai/api/v1")
prompt = ChatPromptTemplate.from_messages([
    ("system", "You are a helpful assistant."),
    ("human", "{input}"),
    ("placeholder", "{agent_scratchpad}"),
])
agent = create_tool_calling_agent(llm, [get_word_count], prompt)
executor = AgentExecutor(agent=agent, tools=[get_word_count])
print(executor.invoke({"input": "How many words in 'hello world foo bar'?"}))

auto:free vs Specific Model — When to Switch

Use caseModelWhy
Prototyping, prompt iteration, dev loopauto:freeZero cost, no quota worries, good enough for most tasks
Tool-calling agents in productionopenai/gpt-4o-miniGuaranteed function-call support and deterministic behavior
Long context / document processinggoogle/gemini-flash-1.51M token context window, fast, low cost
Code generationdeepseek/deepseek-coder-v2Strong coding benchmark, available on free tier
Complex reasoning chainsanthropic/claude-sonnet-4-6Best instruction-following for multi-step reasoning tasks

Switching models is one line. The key, endpoint, and all LangChain code stay the same — just change the model parameter.

Rate Limits on the Free Tier

BazaarLink's free tier limits apply regardless of which model you use via auto:free:

  • 10 requests/minute — sufficient for development and interactive chains
  • 150 requests/day — enough for hundreds of test runs
  • Limits double to 20 RPM / 300/day after your first deposit (even $1 qualifies — no minimum spend required)

For CI pipelines or high-frequency batch processing, add a small amount of credits and switch to a paid model to remove the daily cap.

Bonus: LangChain Agents That Provision Their Own Keys

If you're building a system where LangChain agents spin up dynamically — multiple instances, auto-scaling, or sub-agents — BazaarLink lets each agent register its own API key at startup with no human intervention:

import requests
from langchain_openai import ChatOpenAI

def bootstrap_agent(name: str) -> ChatOpenAI:
    # Agents get their own key — no shared credentials
    api_key = requests.post(
        "https://bazaarlink.ai/api/v1/agents/register",
        json={"name": name},
    ).json()["api_key"]
    return ChatOpenAI(
        model="auto:free",
        openai_api_key=api_key,
        openai_api_base="https://bazaarlink.ai/api/v1",
    )

# Each instance gets its own identity and usage tracking
worker_1 = bootstrap_agent("worker-1")
worker_2 = bootstrap_agent("worker-2")

Each registered agent gets its own key and free credits, and its usage shows up separately in your dashboard — making it easy to track which agents are consuming the most tokens. See the full guide: AI Agents That Provision Their Own API Keys.

Verify Your LangChain Setup

Before deploying, use BazaarLink Probe to verify the endpoint is returning the model you expect. Probe runs 35 automated checks — response integrity, token count accuracy, latency — and gives a 0–100 quality score. Paste your base_url and key and it takes under 2 minutes.

立即體驗 BazaarLink

台幣計費・統一發票・主流 AI 模型・OpenAI 相容 API

免費註冊 / 登入企業採購洽詢
相關文章
free LLM API · free AI API · OpenAI compatible API · developer guide · 2026
Best Free LLM API 2026 — No Credit Card, No Trial Expiry (5 Tested + 10 More)
AI agent · LangChain · CrewAI · AutoGen · free LLM API · agent automation
AI Agents That Provision Their Own API Keys — LangChain, CrewAI & AutoGen Guide
Support
Support
Hi! How can we help you?
Send a message and we'll get back to you soon.