API referencePlatform APIEndpoint reference
GUIDE & REFERENCE

/api/v1/tenants/[id]/scale (management)

Source-derived management endpoint contract, authentication, request validation, responses, and errors.

This is the management service route. Its origin and authentication are described in Platform API overview and Authentication. A path shared by another service is a different endpoint.

PropertyContract
MethodsPOST
Path/api/v1/tenants/[id]/scale
Path parametersid
Query parameters read in routeNone read directly; schema validation below may define additional fields
Headers read in routeNo additional direct header reads; authentication helpers may read credentials

Authentication and access

Management auth context: validated x-api-key or configured session authentication; trusted gateway integration may select its auth pipeline. Organization/tenant checks are separate.

Request and response definitions

The following named definitions are imported or declared by this route. Optional markers, defaults, bounds, and enum values are shown exactly as implemented. A response type is a source contract, not an example populated with real account data.

ScalingRequest

ScalingRequest = z.object({
  target_shards: z.number().int().min(1).max(100),
  reason: z.string().max(500).optional(),
})

Source: minds-ui/apps/api-service/types/operations.ts:39.

ScalingRequest

export type ScalingRequest = z.infer<typeof ScalingRequest>

Source: minds-ui/apps/api-service/types/operations.ts:44.

ScalingResponse

ScalingResponse = z.object({
  id: z.string(),
  current_shards: z.number().int(),
  target_shards: z.number().int(),
  status: z.literal('scaling'),
  estimated_duration: z.number().int(), // seconds
})

Source: minds-ui/apps/api-service/types/operations.ts:50.

ScalingResponse

export type ScalingResponse = z.infer<typeof ScalingResponse>

Source: minds-ui/apps/api-service/types/operations.ts:58.

RouteContext

interface RouteContext {
  params: Promise<{ id: string }>
}

Source: minds-ui/apps/api-service/app/api/v1/tenants/[id]/scale/route.ts:18.

Method behavior

The handler excerpt preserves field validation, response envelopes, cookie changes, and exception branches. Values returned by service helpers retain their named response type above; for passthrough routes, the upstream response is authoritative.

POST

export async function POST(request: NextRequest, context: RouteContext) {
  const requestId = generateRequestId()
  const { id } = await context.params
  let rateLimitInfo: RateLimitMetadata | undefined

  try {
    const tenantId = validateTenantId(id)
    const scalingRequest = await validateBody(request, ScalingRequest)
    const authContext = await resolveAuthContext(request)

    const evaluation = await enforceRateLimit({
      context: authContext,
      tenantId,
    })

    rateLimitInfo = {
      ...evaluation.metadata,
      retryAfter: evaluation.retryAfter,
    }

    if (evaluation.blocked) {
      throw new RateLimitExceededError(evaluation.retryAfter ?? 60)
    }

    const response = await triggerScaling(tenantId, scalingRequest)
    const payload = apiAccepted<ScalingResponse>(response)
    return withRequestMetadata(payload, requestId, rateLimitInfo)
  } catch (error) {
    if (error instanceof ApiError) {
      const response = apiError(error, requestId)
      return withRequestMetadata(response, requestId, rateLimitInfo)
    }
    console.error('Failed to trigger scaling:', error)
    const response = apiError(
      new ApiError(500, 'INTERNAL_ERROR', 'Failed to trigger scaling'),
      requestId,
    )
    return withRequestMetadata(response, requestId, rateLimitInfo)
  }
}

Source: minds-ui/apps/api-service/app/api/v1/tenants/[id]/scale/route.ts:22.

Response and error branches

Literal HTTP statuses in the route: 500. Shared management error classes are defined in Errors and responses.

new RateLimitExceededError(evaluation.retryAfter ?? 60)

Source: minds-ui/apps/api-service/app/api/v1/tenants/[id]/scale/route.ts:43.

apiAccepted<ScalingResponse>(response)

Source: minds-ui/apps/api-service/app/api/v1/tenants/[id]/scale/route.ts:47.

apiError(error, requestId)

Source: minds-ui/apps/api-service/app/api/v1/tenants/[id]/scale/route.ts:51.

apiError(
      new ApiError(500, 'INTERNAL_ERROR', 'Failed to trigger scaling'),
      requestId,
    )

Source: minds-ui/apps/api-service/app/api/v1/tenants/[id]/scale/route.ts:55.

new ApiError(500, 'INTERNAL_ERROR', 'Failed to trigger scaling')

Source: minds-ui/apps/api-service/app/api/v1/tenants/[id]/scale/route.ts:56.

Service dependencies

  • minds-ui/apps/api-service/lib/api-response.ts
  • minds-ui/apps/api-service/lib/validation.ts
  • minds-ui/apps/api-service/types/operations.ts
  • minds-ui/apps/api-service/types/errors.ts
  • minds-ui/apps/api-service/lib/services/auth-context.ts
  • minds-ui/apps/api-service/lib/services/tenant-service.ts
  • minds-ui/apps/api-service/lib/services/rate-limit.ts

Evidence

Generated from the local source snapshot on 2026-09-12. This page documents implemented code and does not certify a deployed service, permissions configuration, or successful provider operation.

Source file: minds-ui/apps/api-service/app/api/v1/tenants/[id]/scale/route.ts. SHA-256: 6008baca1866b93b6341e9577568f4aaf29cb12939e32cae97e08cd93481fdf2.

On this page