Skip to main content

Vercel installation

With your public site served by a Vercel project, connect camolabs without changing normal browsing. Middleware passes traffic to your existing site by default and routes only eligible agent requests to camolabs.

  1. A CNAME for the Agent domain.
  2. Middleware in the project that serves the main domain.

Before you start

You need:

  • access to the Vercel project that serves www.yourdomain.com;
  • access to the DNS provider for yourdomain.com;
  • permission to add environment variables;
  • a published page in camolabs.

If Vercel manages DNS for the domain, use the domain's DNS settings. Vercel's DNS records guide shows the fields.

1. Save the Agent domain

In camolabs, go to Settings > Install.

Enter:

agents.yourdomain.com

Click Save.

2. Add the CNAME

In your DNS provider, add:

FieldValue
TypeCNAME
Nameagents
Valueapp.camolabs.ai

If Vercel manages DNS:

  1. Open the Vercel dashboard.
  2. Go to Domains.
  3. Select yourdomain.com.
  4. Add the CNAME above.

After the record saves, return to camolabs and click Test DNS.

3. Add the environment variable

In the Vercel project that serves the main domain, add:

NameValue
CAMOLABS_AGENT_ORIGINhttps://agents.yourdomain.com

Apply it to Production. Add Preview and Development only if you need to test those environments.

4. Add Middleware

Install the edge adapter:

npm install @camolabs/edge-adapter

Create or update middleware.ts in the project root:

import { NextResponse, type NextRequest } from "next/server";
import { prepareOriginUrl, routeAgentRequest } from "@camolabs/edge-adapter";

export async function middleware(request: NextRequest) {
const agentResponse = await routeAgentRequest(request, {
agentOrigin: process.env.CAMOLABS_AGENT_ORIGIN!,
});

if (agentResponse) {
return new NextResponse(agentResponse.body, {
status: agentResponse.status,
headers: agentResponse.headers,
});
}

const originUrl = prepareOriginUrl(request);
return originUrl ? NextResponse.rewrite(originUrl) : NextResponse.next();
}

export const config = {
matcher: ["/((?!api|_next|.*\\..*).*)"],
};

routeAgentRequest returns an Agent Page only when camolabs should handle the request. prepareOriginUrl removes camolabs validation and origin request parameters before traffic continues to your original site.

Deploy the project.

5. Test routing

In camolabs, go to Settings > Install and click Test routing.

You can also run:

curl -i https://www.yourdomain.com/pricing \
-H "User-Agent: python-requests/2.31"

Expected Agent Page response:

HTTP/2 200
x-camolabs-agent-page-outcome: served_agent_page
content-type: text/html; charset=utf-8

If the Agent Page is missing, unpublished, or camolabs is unavailable, Middleware continues to the existing site.

Runtime behavior

Middleware:

  • passes traffic to your existing site by default;
  • asks camolabs only when the routing policy allows the request;
  • skips browser navigations, search crawlers, assets, APIs, and excluded paths;
  • requests the same path from https://agents.yourdomain.com;
  • returns camolabs output only when the response is an Agent Page;
  • removes camolabs validation and origin request parameters before rewriting to origin.