Menu

Building a Chat Interface Over Any API with TypeScript
πŸ“°

Building a Chat Interface Over Any API with TypeScript

DEV CommunityΒ·Pavel EspitiaΒ·7 months ago
#ylEQXpFx
#typescript#ai#webdev#function#const
Reading 0:00
15s threshold

Most AI chat interfaces do the same thing: the user types a message, the LLM generates text, and it appears on screen. But the interesting pattern is when the LLM does something β€” calls an API, queries a database, runs a command β€” and then explains what happened.

I built this pattern into AbiLens, a tool that lets you chat with any EVM smart contract. But the architecture generalizes to any external API. You can use the same approach to build a chat interface over a REST API, a database, a CLI tool, or any service with a programmatic interface.

Here's how it works.

The Architecture

The flow has four steps:

User sends a message

LLM decides what API call to make (or responds directly if no call is needed)

Your code executes the API call

LLM explains the result to the user

The key insight: the LLM never calls the API directly. It outputs a structured JSON object describing the call it wants to make. Your code validates and executes it.…

Continue reading β€” create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.