DEV Community

APIVAI
APIVAI

Posted on • Originally published at apivai.com

How to Build a LINE AI Bot with APIVAI (Cheap Claude & GPT)

Build a LINE AI bot with APIVAI

LINE is huge across Japan, Taiwan, and Thailand, making a LINE AI bot a great support or assistant
channel. Use the LINE Messaging API webhook plus an OpenAI-compatible model for replies — APIVAI
provides Claude/GPT cheaply, and GPT-5.5 handles multilingual chat well.

1. Set up the LINE channel

  • In the LINE Developers Console, create a Messaging API channel.
  • Get the Channel access token and set the Webhook URL to your server's /line endpoint.

2. The webhook server (Node)

import express from "express";
import OpenAI from "openai";
const app = express(); app.use(express.json());
const ai = new OpenAI({ apiKey: process.env.APIVAI_API_KEY, baseURL: "https://api.apivai.com/v1" });

app.post("/line", async (req, res) => {
  res.sendStatus(200);
  for (const ev of req.body.events || []) {
    if (ev.type !== "message" || ev.message.type !== "text") continue;
    const r = await ai.chat.completions.create({
      model: "gpt-5.5",
      messages: [{ role: "system", content: "You are a helpful assistant. Reply in the user's language." },
                 { role: "user", content: ev.message.text }],
      max_tokens: 400,
    });
    await fetch("https://api.line.me/v2/bot/message/reply", {
      method: "POST",
      headers: { Authorization: `Bearer ${process.env.LINE_TOKEN}`, "Content-Type": "application/json" },
      body: JSON.stringify({ replyToken: ev.replyToken, messages: [{ type: "text", text: r.choices[0].message.content }] }),
    });
  }
});
app.listen(3000);
Enter fullscreen mode Exit fullscreen mode

Set LINE_TOKEN + APIVAI_API_KEY, expose the webhook to LINE, and message your bot.

Polish

  • Keep short per-user history for context; trim to control cost.
  • Use quick replies / rich menus for common actions.
  • GPT-5.5 for multilingual support; a smaller model for bulk/simple replies.

FAQ

Can a LINE bot use APIVAI? Yes — it's an OpenAI chat call with base URL
https://api.apivai.com/v1; the webhook forwards the message and replies.

Which model for LINE support? GPT-5.5 — strong multilingual (JP/zh/TH), low latency, cheap.

How do I control cost? Trim history and cap max_tokens.

Get started

Create a LINE Messaging API channel, run the webhook with your APIVAI key, and message the bot.
Examples: APIVAI examples repo.

Top comments (0)