Cheaper Inference
Use the Cheaper Inference OpenAI compatible API with the AI SDK.
Cheaper Inference is an API gateway that provides access to models from multiple AI labs through an OpenAI-compatible API. You can use its Chat Completions endpoint with the AI SDK through the @ai-sdk/openai-compatible module.
Setup
Install the OpenAI Compatible provider:
$ pnpm add @ai-sdk/openai-compatible
$ npm install @ai-sdk/openai-compatible
$ yarn add @ai-sdk/openai-compatible
$ bun add @ai-sdk/openai-compatible
Create a Cheaper Inference API key and set it as a server-side environment variable:
See the Cheaper Inference integration guide for instructions on creating an API key.
Provider Instance
Create a Cheaper Inference provider instance with createOpenAICompatible:
The apiKey setting sends your key as a Bearer token in the Authorization header.
Language Models
Create a language model by passing a Cheaper Inference model ID to the provider instance:
Generate Text
Use generateText to generate text with the model:
Stream Text
Use streamText to stream text as it is generated:
Supported Models and Capabilities
This integration uses Cheaper Inference's OpenAI-compatible Chat Completions endpoint for text generation and streaming. Support for tools, vision, and other model-specific features depends on the selected model.
The model catalog changes over time. Use the authenticated GET /models endpoint to find current model IDs, capabilities, and pricing.