Plugin for Cloudflare AI API

RMAG news

I created a module for @luisfun/cloudflare-ai-plugin, and this is its introduction.

What I Built

This is a plugin that allows you to write REST API and AI Gateway in the same way as binding AI (env.AI.run) when using Cloudflare’s Workers AI.
Also, it supports Typescript.

How to Use

Install

npm i @luisfun/cloudflare-ai-plugin
npm i -D @cloudflare/ai # When using TypeScript

Coding

import { Ai } from @luisfun/cloudflare-ai-plugin

// const ai = env.AI
const ai = new Ai(env.AI_API_URL, env.AI_API_TOKEN)

const response = await ai.run(model, inputs)

How to get API URL and TOKEN

There are also some extensions available.
Here, I will include the cache control of the Gateway.
If you are interested in other extensions, please check the repository.

const options = {
cf-skip-cache: true,
cf-cache-ttl: 60,
}
const response = await ai.run(model, inputs, options)

Repository

https://github.com/LuisFun/cloudflare-ai-plugin

Leave a Reply

Your email address will not be published. Required fields are marked *