DEV Community

Ateeb Ur Rahmaan
Ateeb Ur Rahmaan

Posted on

npm-ai-hooks: Inject LLM behavior into any TS function with one line

Hey everyone ๐Ÿ‘‹

Iโ€™ve been working on something I wish existed earlier โ€” npm-ai-hooks โ€” a universal AI hook layer for Node.js and TypeScript.

It lets you inject LLM behavior into any JS/TS function with just one line.
No need to manage SDKs, prompts, or API differences between providers.

import { ai } from "npm-ai-hooks";

const summarize = ai.wrap(t => t, { task: "summarize" });

console.log(await summarize("Node.js is a JavaScript runtime built on Chromeโ€™s V8..."));
Enter fullscreen mode Exit fullscreen mode

Thatโ€™s it โ€” you just made a function โ€œAI-aware.โ€


๐Ÿš€ What makes it cool

  • Works with OpenAI, Claude, Gemini, DeepSeek, Groq, Mistral, Perplexity, xAI Grok, and OpenRouter
  • Unified interface for all providers
  • Built-in tasks: summarize, translate, rewrite, codeReview, explain, etc.
  • Handles caching, cost-awareness, and errors automatically
  • Fully open source (MIT)

๐Ÿ’ก Why I built it

Every AI SDK feels different โ€” with its own setup, auth, and quirks.
I wanted something like React Hooks, but for backend AI logic.

So now you can do:

const reviewCode = ai.wrap(code => code, { task: "codeReview" });
Enter fullscreen mode Exit fullscreen mode

and get meaningful results without writing a single prompt.


๐Ÿ”— Links


Iโ€™d love your thoughts and contributions โ€” new features, provider ideas, or improvements are all welcome.
If you like the concept, try it, star it, and letโ€™s build an AI abstraction layer that just works โœจ

Top comments (0)