Building a Product with Nascentist

A practical guide for integrating Nascentist into production applications.

1. Architecture: where Nascentist fits

Place Nascentist behind your application backend, not directly in browser clients. Your backend should own API key usage, request shaping, retries, and logging.

2. Client vs server-side

Always call Nascentist from server routes or workers. Browser calls expose credentials and reduce your control over observability and rate limits.

3. Managing API keys securely

  • Store keys in server environment variables or a secret manager.
  • Use scoped keys for specific products or teams.
  • Rotate keys regularly and revoke unused keys quickly.

4. Handling errors in production

Classify errors into retryable (429, 500, 503) and fatal (400, 401, 403). Emit structured logs for every request ID and upstream status code.

Note
Keep user-facing fallback text separate from raw provider error messages.

5. Cost optimization strategies

  • Lower max_tokens for bounded tasks.
  • Use /v1/complete for simple generation and escalate only when needed.
  • Cache stable outputs like lint explanations and template snippets.

6. Scaling and rate limit planning

Model peak requests per minute and expected token bursts. Add queues for heavy agentic workloads and enforce per-user budgets before global limits are hit.

7. Example: Next.js code review bot

26 lines
import { NextResponse } from "next/server";

export async function POST(request: Request) {
  const { code } = await request.json();

  const upstream = await fetch("https://api.nascentist.ai/v1/agent/review", {
    method: "POST",
    headers: {
      Authorization: `Bearer ${process.env.NASCENTIST_API_KEY}`,
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      model: "nascentist-1",
      code,
      language: "typescript",
    }),
  });

  if (!upstream.ok) {
    const error = await upstream.text();
    return NextResponse.json({ error }, { status: upstream.status });
  }

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