This cookbook builds a minimal but production-shaped chatbot: a backend that proxies 123API’s chat endpoint with streaming, and a tiny frontend that renders tokens as they arrive. Total code is under 60 lines.
Architecture #
Browser → your backend → 123API chat endpoint → model. Keeping the key server-side is non-negotiable; never expose it to the browser.
Step 1 — Backend endpoint (Node.js) #
Step 2 — Frontend (streaming) #
Read the Server-Sent Events stream and append delta.content to the chat box. For the streaming format, see Core Capabilities.
Step 3 — Add tools with function calling #
Let the model call your API (weather, search) via function calling. This is what turns a chatbot into an agent.
Production tips #
- Cap timeouts and add retries — see rate limits and retries.
- Route cheap chit-chat to smaller models using the cost guide.
- New here? Begin with the quickstart guide.
FAQ
Do I need a framework? No — the snippet above is plain Node.js. How do I keep my key safe? Call 123API from your backend only.
Suggested internal links (positions)
- “proxies 123API’s chat endpoint” → 123API chat endpoint (anchor: “123API chat endpoint”).
- “For the streaming format, see [Core Capabilities]” → Core Capabilities (anchor: “Core Capabilities”).
- “via [function calling]” → function calling (anchor: “function calling”).
- “see [rate limits and retries]” → rate limits and retries (anchor: “rate limits and retries”).
- “[cost guide]” → cost guide (anchor: “cost guide”).
- “[quickstart guide]” → quickstart guide (anchor: “quickstart guide”).