Integrations

Vercel AI SDK

Create a named OpenAI-compatible provider for PromptsForLess in the Vercel AI SDK, with generateText and streamText examples.

Create a named OpenAI-compatible provider to send AI SDK requests to PromptsForLess. This follows the AI SDK's compatible provider documentation and works on any host, not only Vercel.

Install

pnpm add ai @ai-sdk/openai-compatible

Store your key from the dashboard as PFL_API_KEY in your server environment. Keep it out of public environment variables and client code.

Create a provider

Server-side generation
import { createOpenAICompatible } from '@ai-sdk/openai-compatible';
import { generateText } from 'ai';

const pfl = createOpenAICompatible({
  name: 'promptsforless',
  baseURL: 'https://api.promptsforless.com/v1',
  apiKey: process.env.PFL_API_KEY,
});

const result = await generateText({
  model: pfl('deepseek-v4.1-flash'),
  prompt: 'Write one friendly sentence welcoming a new developer.',
});

console.log(result.text);
console.log(result.usage);

Swap in any model ID from the catalog. Always pass pfl(modelId): a bare model string makes the SDK pick its own default provider.

Stream a response

import { streamText } from 'ai';

const result = streamText({
  model: pfl('deepseek-v4.1-flash'),
  prompt: 'Write a brief greeting.',
});

for await (const part of result.textStream) {
  process.stdout.write(part);
}

See the streamText reference for options. For a browser chat UI, stream from a server route that holds the key; never create this provider in the browser.

Add tools and structured output

The AI SDK's tools option and structured output helpers work with PromptsForLess. Pick a model that supports the feature you need, such as tool calling or image input.

Troubleshooting

SymptomFix
Key is missingCheck that the server process can read PFL_API_KEY.
Requests go to a different providerPass pfl(modelId) to every generation call.
Invalid request parameterRemove optional settings, check your SDK version's docs, then add options back one at a time.

Use the quickstart to test HTTP directly and the catalog to compare prices.

On this page