How to Use DGrid AI Gateway with the Vercel AI SDK

· Source: LLM on Medium · Field: Technology & Digital — Artificial Intelligence & Machine Learning, Software Development & Engineering · Depth: Intermediate, medium

Summary

This guide details how to integrate the Vercel AI SDK with the DGrid AI Gateway to build AI-powered applications. It outlines a step-by-step process for setting up a minimal Next.js project, configuring the DGrid provider, and implementing both simple text generation and streaming chat functionalities. The workflow was validated using DGrid's base URL `https://api.dgrid.ai/v1`, the `openai/gpt-5.4` model format, the Vercel AI SDK with `@ai-sdk/openai-compatible`, and the Next.js App Router. Key steps include installing `ai`, `@ai-sdk/openai-compatible`, and `@ai-sdk/react` packages, setting the `DGRID_API_KEY` environment variable, and creating a DGrid provider using `createOpenAICompatible` with the correct `baseURL` and provider-prefixed model IDs.

Key takeaway

For AI Engineers building Next.js applications with the Vercel AI SDK who need to route model traffic through DGrid AI Gateway, ensure you configure `createOpenAICompatible` with `baseURL: 'https://api.dgrid.ai/v1'` and use DGrid's provider-prefixed model IDs like `openai/gpt-5.4`. This setup enables both non-streaming and streaming chat functionalities, streamlining your model integration and deployment to platforms like Vercel.

Key insights

Integrate Vercel AI SDK with DGrid AI Gateway for AI applications using an OpenAI-compatible interface.

Principles

Method

Configure `createOpenAICompatible` with DGrid's base URL and API key. Implement `generateText` for single completions and `streamText` with `convertToModelMessages` for streaming chat, connecting to a React UI via `useChat`.

In practice

Topics

Best for: AI Engineer, Software Engineer, AI Chatbot Developer

Related on AIssential

Open in AIssential →

Editorial summary, takeaway, and curation by AIssential. Original article published by LLM on Medium.