# Vercel Hosting Deploy apps to Vercel by sending files as JSON. One POST to deploy. ## Prerequisites Provision this resource before use. Edge requests without provisioning will error. ### Provision curl -s -X POST https://cohesivity.ai/api/resources/vercel-hosting \ -H "Authorization: Bearer " ### Delete curl -s -X DELETE https://cohesivity.ai/api/resources/vercel-hosting \ -H "Authorization: Bearer " **Important:** Provision this resource now, before building or running the application. Provisioning is the agent's job, not the application's. ## Common Mistakes - **Setting `NEXT_PUBLIC_*` env vars after the first deploy.** In Next.js, these are baked at build time. Set all env vars via `POST /api/vercel/env` **before** the first deploy. If you add or change them later, redeploy. - **Not setting maxDuration for slow routes.** Vercel default serverless timeout is 10s. For slow routes (AI, image processing), add `export const maxDuration = 60;` at the top of the route file. - **Using create-next-app or other interactive scaffolders.** Write your files directly — interactive scaffolders fail in agent environments. Write package.json manually. ## What Happens on Provision - Creates a Vercel project: `coh-` - Returns `deployment_url` (e.g. `https://coh-.vercel.app`) ## How to Deploy The provisioning response includes a `deploy_script` field — a ready-to-use shell script. Save it and run it: # Save the script from the provisioning response chmod +x deploy.sh && ./deploy.sh The script collects all project files (skipping node_modules, .next, .git, .env), encodes them as JSON, and deploys. Works on Mac, Linux, WSL, CI. Alternatively, call the deploy API directly: 1. Provision `vercel-hosting` — response has `deployment_url` and `deploy_script` 2. Set env vars (if needed): `POST https://cohesivity.ai/api/vercel/env` with `{ "key": "...", "value": "..." }` 3. Deploy: ``` POST https://cohesivity.ai/api/vercel/deploy Authorization: Bearer Content-Type: application/json { "files": [ { "file": "index.html", "data": "..." }, { "file": "style.css", "data": "body { ... }" }, { "file": "package.json", "data": "{\"name\": \"my-app\", ...}" } ], "projectSettings": { "framework": "nextjs" } } ``` Response: `{ "deployment_id": "...", "url": "https://...", "status": "INITIALIZING", "project_url": "https://coh-.vercel.app" }` `projectSettings` is optional. If omitted, Vercel auto-detects the framework. Set `"framework": "nextjs"` for Next.js apps. For binary files (images, fonts), use base64 encoding: `{ "file": "logo.png", "data": "", "encoding": "base64" }` Max payload size: 10 MB. A typical Next.js app with 30-50 source files is well within this limit. 4. Site is live at `deployment_url` (stable production URL). ## Redeploy To update, call `POST /api/vercel/deploy` again with the new files. The production URL stays the same. ## Deployment Management All endpoints require `Authorization: Bearer ` header. - **List deployments:** `GET https://cohesivity.ai/api/vercel/deployments` - **Deployment details:** `GET https://cohesivity.ai/api/vercel/deployments/:id` - **Cancel deployment:** `POST https://cohesivity.ai/api/vercel/deployments/:id/cancel` - **Build logs:** `GET https://cohesivity.ai/api/vercel/deployments/:id/logs` ## Environment Variables All endpoints require `Authorization: Bearer ` header. - **List env vars:** `GET https://cohesivity.ai/api/vercel/env` - **Create env var:** `POST https://cohesivity.ai/api/vercel/env` with `{ "key": "MY_SECRET", "value": "abc123", "target": ["production"] }` - **Delete env var:** `DELETE https://cohesivity.ai/api/vercel/env/:key` ## Security Never expose keys in frontend code. Store secrets as Vercel env vars via the endpoint above.