Skip to main content
This tutorial adds one authenticated application route between your browser and Praxa. The browser never receives the Praxa API key.

Prerequisites

  • Next.js App Router with TypeScript
  • Your application session helper
  • A personal Praxa key with execute:write
  • Node.js 20 or newer
Next.js Route Handlers use the Web Request and Response APIs. Keep PRAXA_API_KEY unprefixed: variables beginning with NEXT_PUBLIC_ are eligible for the browser bundle.

1. Add the server-only client

lib/praxa.server.ts
The hash binds the caller’s stable application request ID to the authenticated user without exposing that user ID to Praxa.

2. Add the Route Handler

app/api/tasks/route.ts
Do not accept a Praxa tenant, workspace, owner, scope, or API key in the browser request. Your session and server configuration own that authority.

3. Call it from the client

Persist requestId until the request settles. Reuse it after a timeout; create a new value only for new logical work.

4. Test the boundary

Mock the upstream request in a Route Handler test and prove:
  1. No session returns 401 before the Praxa call.
  2. Invalid input returns 400 before the Praxa call.
  3. A valid request forwards one server-owned key and no browser-supplied owner.
  4. Repeating the same user and request ID emits the same idempotency key.
  5. Changing either value emits a different idempotency key.
  6. The response uses Cache-Control: no-store.
Then run one disposable live task and follow its run to a terminal state. A 202 response proves admission, not completion.

Troubleshooting

Best practices

  • Import server-only in credential-owning modules.
  • Keep the key unprefixed and scan built client chunks for credential patterns.
  • Authenticate and bound the body before calling Praxa.
  • Rate-limit per application principal.
  • Store the request ID with the draft before the first mutation.
  • Add a server-owned run-read route instead of exposing the Praxa key.
  • Test Node and edge runtimes separately if your deployment uses both.

Next.js Route Handler reference

Review the current framework conventions in the official Next.js guide.

Optimize for production

  • Reuse one configured HTTP or SDK client per process and bound concurrent upstream work.
  • Prefer durable admission plus asynchronous readback over holding application requests open.
  • Cache only non-sensitive, tenant-scoped reads within their documented freshness window.
  • Measure p50/p95 latency, admission-to-terminal time, retries, conflicts, and connection reuse before tuning.
Optimize only after the correctness and isolation matrix passes. Lower latency or cost is not an improvement if verified outcomes, authority checks, or recovery rates regress.

Cleanup and next steps

  1. Revoke the disposable Praxa key and require a later request to fail.
  2. Remove synthetic application records and any temporary environment files.
  3. Cancel or archive unresolved test runs according to the application policy.
  4. Retain only redacted request, run, and verification identifiers needed for the test record.
After cleanup, run the shared integration test matrix and record any environment-specific check that remains pending.

Frequently asked questions

What proves this tutorial works?

The minimum observable result is that the App Router keeps credentials server-only and returns a bounded task projection. A compile, package import, mocked response, or initial admission alone does not prove the complete workflow.

Can a browser, mobile app, or model prompt hold the credential?

No. Browser and mobile bundles are inspectable. Keep the Praxa credential in the trusted application backend.

How should an ambiguous mutation be retried?

Persist the exact logical input and idempotency key before the first attempt. Reconcile through authoritative readback or replay the exact request with that same key before creating new work.

What should we monitor after release?

Monitor application auth failures, upstream status/code, latency, retries, replay conflicts, and terminal run outcomes. Alert on authorization bypass, cross-tenant disclosure, repeated conflicts, or cleanup failure.
Last modified on August 14, 2026