---
title: "Vercel"
description: "Deploy Next.js apps and serverless functions that call APIBrasil — over MCP or REST — on the Vercel platform."
lang: en
canonical: https://doc.apibrasil.io/mcp/plataformas-cloud/vercel
markdown: https://doc.apibrasil.io/mcp/plataformas-cloud/vercel.md
source: apibrasil-documentation
---

# Vercel

> Deploy Next.js apps and serverless functions that call APIBrasil — over MCP or REST — on the Vercel platform.

- **Category:** Cloud platforms
- **Difficulty:** Medium
- **Protocol:** calls the REST gateway over HTTP
- **Updated on:** January 14, 2026

## Prerequisites

- A Vercel account
- A Next.js or Node.js project
- Vercel CLI installed (optional)
- APIBrasil tokens

## Configuration

- **File:** `api/consultar-cep.ts`

```typescript
import { NextRequest, NextResponse } from 'next/server';

export const config = {
  runtime: 'edge', // ou 'nodejs'
};

export default async function handler(req: NextRequest) {
  const { cep } = await req.json();

  const response = await fetch('https://gateway.apibrasil.io/api/v2/cep/cep', {
    method: 'POST',
    headers: {
      'Authorization': `Bearer ${process.env.APIBRASIL_BEARER_TOKEN}`,
      'DeviceToken': process.env.APIBRASIL_DEVICE_TOKEN || '',
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({ cep }),
  });

  const data = await response.json();
  return NextResponse.json(data);
}
```

## Step by step

1. **Create a serverless function** — Add a file under the /api folder of your Next.js project
   ```typescript
   // api/consultar-cep.ts
   import { NextRequest, NextResponse } from 'next/server';
   
   export default async function handler(req: NextRequest) {
     const { cep } = await req.json();
     
     const response = await fetch('https://gateway.apibrasil.io/api/v2/cep/cep', {
       method: 'POST',
       headers: {
         'Authorization': `Bearer ${process.env.APIBRASIL_BEARER_TOKEN}`,
         'DeviceToken': process.env.APIBRASIL_DEVICE_TOKEN || '',
         'Content-Type': 'application/json',
       },
       body: JSON.stringify({ cep }),
     });
     
     return NextResponse.json(await response.json());
   }
   ```
2. **Set the environment variables** — In the Vercel dashboard, go to Settings > Environment Variables and add your tokens
3. **Add them to .env.local** — For local development, create a .env.local file
   ```bash
   APIBRASIL_BEARER_TOKEN=seu_bearer_token
   APIBRASIL_DEVICE_TOKEN=seu_device_token
   ```
4. **Deploy to Vercel** — Push to the repository, or use the Vercel CLI
   ```bash
   # Via CLI:
   vercel --prod
   
   # Via Git:
   git push origin main
   ```
5. **Test the API** — Call your function at https://your-project.vercel.app/api/consultar-cep
   ```bash
   curl -X POST https://seu-projeto.vercel.app/api/consultar-cep \
     -H 'Content-Type: application/json' \
     -d '{"cep": "01001000"}'
   ```

## Troubleshooting

- **The environment variables are not loaded** — Make sure you added the variables to EVERY environment (Production, Preview, Development) in the Vercel dashboard
- **Timeout on the Edge Runtime** — The Edge Runtime caps at 30s. For longer look-ups, set runtime: 'nodejs' in the config
- **CORS error** — Add the CORS headers to your API route
  ```
  return NextResponse.json(data, {
    headers: {
      'Access-Control-Allow-Origin': '*',
      'Access-Control-Allow-Methods': 'POST, OPTIONS',
    },
  });
  ```
- **The build fails** — Check that every dependency you need is in package.json

## Related links

- [Vercel documentation](https://vercel.com/docs)
- [Next.js API Routes](https://nextjs.org/docs/api-routes/introduction)
- [Deploy with Cloudflare](https://doc.apibrasil.io/mcp/plataformas-cloud/cloudflare.md)
- [Next.js examples with APIBrasil](https://doc.apibrasil.io/mcp/exemplos/nextjs.md)

## See also

- MCP guide: [MCP guide](https://doc.apibrasil.io/mcp.md)
- Documentation index: https://doc.apibrasil.io/llms.txt
- HTML version of this page: https://doc.apibrasil.io/mcp/plataformas-cloud/vercel
