Heroku
Use a Heroku OpenAI compatible API with the AI SDK.
Heroku is a cloud platform that allows you to deploy and run applications, including AI models with OpenAI API compatibility. You can deploy models that are OpenAI API compatible and use them with the AI SDK.
Setup
The Heroku provider is available via the @ai-sdk/openai-compatible module as it is compatible with the OpenAI API.
You can install it with
$ pnpm add @ai-sdk/openai-compatible
$ npm install @ai-sdk/openai-compatible
$ yarn add @ai-sdk/openai-compatible
$ bun add @ai-sdk/openai-compatible
Heroku Setup
- Create a test app in Heroku, replacing
your-app-namewith a unique app name:
- Inference using claude-3-5-haiku:
- Export Variables:
Provider Instance
To use Heroku, you can create a custom provider instance with the createOpenAICompatible function from @ai-sdk/openai-compatible:
Be sure to have your INFERENCE_KEY, INFERENCE_MODEL_ID, and INFERENCE_URL set in your environment variables.
Language Models
You can create Heroku models using a provider instance.
The first argument is the served model name, e.g. claude-3-5-haiku.
Example
You can use Heroku language models to generate text with the generateText function:
Heroku language models are also able to generate text in a streaming fashion with the streamText function:
Heroku language models also support structured data generation with Output.