Introducing hubAI()
Run machine learning models, such as LLMs in your Nuxt application, with minimal setup.
This feature is available on both free and pro plans and in
@nuxthub/core >= v0.7.2
.We are excited to introduce hubAI()
. This new method allows you to run machine learning models, such as LLMs, directly within your Nuxt application with minimal setup.
At NuxtHub, we care about DX and we want to make it easy for you to leverage AI in your application using Cloudflare AI without having to manage API keys, account ID or using the wrangler
CLI.
How to use hubAI()
- Update
@nuxthub/core
to the latest version (v0.7.2
or later) - Enable
hub.ai
in yournuxt.config.ts
nuxt.config.ts
export default defineNuxtConfig({
hub: {
ai: true
},
})
- Run
npx nuxthub link
to link a NuxtHub project or create a new one - You can now use
hubAI()
in your server routes
server/api/ai-test.ts
export default defineEventHandler(async (event) => {
return await hubAI().run('@cf/meta/llama-3.1-8b-instruct', {
prompt: 'Who is the author of Nuxt?'
})
})
Read the full documentation to learn more about hubAI()
.
If you already have a NuxtHub account, make sure to add the
Worker AI
permission on your Cloudflare API token.- Open Cloudflare User API Tokens
- Find the NuxtHub token(s)
- Add the
Account > Worker AI > Read
permission - Save the changes
Link a new account
> Create a token with required permissions
.This feature has been implemented in nuxt-hub/core#173.