AI/ML API

Learn how to use the AI/ML API provider.

The AI/ML API provider gives access to more than 300 AI models over an OpenAI-compatible API.

Setup

The AI/ML API provider is available via the @ai-ml.api/aimlapi-vercel-ai module. You can install it with:

$ pnpm add @ai-ml.api/aimlapi-vercel-ai

API Key

Set the AIMLAPI_API_KEY environment variable with your key:

export AIMLAPI_API_KEY="sk-..."

Provider Instance

You can import the default provider instance aimlapi:

import { aimlapi } from '@ai-ml.api/aimlapi-vercel-ai';

Language Models

Create models for text generation with aimlapi and use them with generateText:

import { aimlapi } from '@ai-ml.api/aimlapi-vercel-ai';
import { generateText } from 'ai';

const { text } = await generateText({
  model: aimlapi('gpt-4o'),
  system: 'You are a friendly assistant!',
  prompt: 'Why is the sky blue?',
});

Image Generation

You can generate images by calling doGenerate on an image model:

import { aimlapi } from '@ai-ml.api/aimlapi-vercel-ai';

const model = aimlapi.imageModel('flux-pro');

const res = await model.doGenerate({
  prompt: 'a red balloon floating over snowy mountains, cinematic',
  n: 1,
  aspectRatio: '16:9',
  seed: 42,
  size: '1024x768',
  providerOptions: {},
});

console.log(`✅ Generated image url: ${res.images[0]}`);

Embeddings

AI/ML API also supports embedding models:

import { aimlapi } from '@ai-ml.api/aimlapi-vercel-ai';
import { embed } from 'ai';

const { embedding } = await embed({
  model: aimlapi.textEmbeddingModel('text-embedding-3-large'),
  value: 'sunny day at the beach',
});

For more information and a full model list, visit the AI/ML API dashboard and the AI/ML API documentation.