Skip to content

Never stop coding. Free MIT AI gateway: one endpoint, 375 providers (150+ free), 1,400+ models Kimi, Claude, GPT, Gemini, GLM, DeepSeek, MiniMax. Works with Claude Code, Codex, Cursor, OpenCode, Cline & Copilot. Quota-aware auto-fallback, RTK+Caveman compression saves 15-95% tokens, MCP/A2A, Desktop/PWA. Built by 900+ contributors

726 B
Raw Blame
import { NextResponse } from "next/server";
import { requireManagementAuth } from "@/lib/api/requireManagementAuth";
import { createTraeLoginState } from "@/lib/oauth/traeLoginState";

/**
 * POST /api/oauth/trae/authorize-state
 *
 * Issues the one-time state that the dashboard sends to Trae as `login_trace_id`.
 * The loopback callback at /authorize only saves a connection for a state issued
 * here. `/api/oauth/` is a public prefix, so the management check is done here.
 */
export async function POST(request: Request) {
  const authResponse = await requireManagementAuth(request, { invalidApiKeyStatus: 401 });
  if (authResponse) return authResponse;
  return NextResponse.json({ state: createTraeLoginState() });
}