Settings

Theme

Show HN: I built a lightweight tRPC alternative to ease LLMs working with APIs

github.com

4 points by piterrro 6 months ago · 1 comment

Reader

piterrroOP 6 months ago

After building several full-stack applications, I discovered that Large Language Models (LLMs) face significant challenges when implementing features that span both backend and frontend components, particularly around API interfaces.

The core issues I observed:

- API Contract Drift: LLMs struggle to maintain consistency when defining an API endpoint and then implementing its usage in the frontend

- Context Loss: Without a clear, shared contract, LLMs lack the contextual assistance needed to ensure proper integration between client and server

- Integration Errors: The disconnect between backend definitions and frontend consumption leads to runtime errors that could be prevented

The Solution: Leverage TypeScript's powerful type system to provide real-time feedback and compile-time validation for both LLMs and developers. By creating a shared contract that enforces consistency across the entire stack, we eliminate the guesswork and reduce integration issues. A small NPM module with only dependency of Zod:

https://github.com/PeterOsinski/ts-typed-api

I already used it in a couple of projects and so far so good. LLMs don't get lost even when implementing changes to APIs with dozens of endpoints. I can share a prompt I'm using that instructs LLM how to leverage definitions and find implementations.

Let me know what you think, feedback welcome!

Keyboard Shortcuts

j
Next item
k
Previous item
o / Enter
Open selected item
?
Show this help
Esc
Close modal / clear selection