Next.js

07 Deploy

Check Next.js runtime, provider, and storage requirements before deploying Anvia routes.

Runtime Checklist

AreaCheck
RuntimeUse export const runtime = "nodejs" unless every dependency supports edge execution
SecretsSet provider keys in the deployment environment, not in client bundles
StreamingDisable buffering in proxies that sit in front of streaming routes
TimeoutsKeep route timeouts above your longest expected model/tool run
StorageUse durable storage for history, memory, traces, and retrieval indexes

Provider Clients

Create clients and models in server modules:

const apiKey = process.env.OPENAI_API_KEY;

if (!apiKey) {
  throw new Error("OPENAI_API_KEY is required");
}

const client = new OpenAIClient({ apiKey });
const model = client.completionModel("gpt-5.5");

Do not expose provider keys to browser code.

Observability

Attach observers when you need logs, traces, or metrics:

const agent = new AgentBuilder("support", model)
  .observe(observer)
  .build();

Use .withTrace(...) per request for route, user, and session metadata.

Deployment Smoke Test

curl -X POST "$APP_URL/api/support" \
  -H "Content-Type: application/json" \
  -d '{"message":"Say hello"}'

Next

Use Troubleshooting when a deployed route behaves differently from local development. Related guides: Observers and Errors.