API referencePlatform APIEndpoint reference
GUIDE & REFERENCE

/api/v1/instances/[instanceId]/services/enable (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/instances/[instanceId]/services/enable
Path parametersinstanceId
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.

EnableServiceRequest

export interface EnableServiceRequest {
  services: ServiceName[];
  strategy?: 'hot-load' | 'new-deployment';
  verifyHealth?: boolean; // Default: true
}

Source: minds-ui/apps/api-service/lib/services/hot-loading-service.ts:38.

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,
  { params }: { params: Promise<{ instanceId: string }> }
) {
  try {
    // Authenticate request
    const authContext = await resolveAuthContext(request, {
      allowApiKey: true,
      allowSession: true,
    });

    const { instanceId } = await params;
    const body = await request.json();

    // Validate request body
    if (!body.services || !Array.isArray(body.services)) {
      throw new InvalidRequestError('services array required');
    }

    // Get instance to verify tenant access
    const instance = await prisma.serviceInstance.findUnique({
      where: { id: instanceId },
      include: { tenant: true },
    });

    if (!instance || !instance.tenant) {
      return NextResponse.json(
        { error: 'Instance not found' },
        { status: 404 }
      );
    }

    // Ensure tenant access
    await ensureTenantAccess(
      authContext,
      instance.tenant.orgId,
      instance.tenant.ownerId,
      {
        action: 'instance:manage',
        tenantId: instance.tenantId ?? undefined,
        resourceId: instance.id,
        attributes: { operation: 'enable-service' },
      }
    );

    const enableRequest: EnableServiceRequest = {
      services: body.services,
      strategy: body.strategy || 'hot-load',
      verifyHealth: body.verifyHealth !== false,
    };

    // Enable services
    const result = await hotLoadingService.enableServiceOnInstance(
      instanceId,
      enableRequest,
      authContext.userId
    );

    return NextResponse.json(result, { status: result.status === 'completed' ? 200 : 207 });
  } catch (error) {
    if (error instanceof ApiError) {
      return NextResponse.json(
        { error: error.message },
        { status: error.statusCode }
      );
    }

    console.error('[API] Error enabling services:', error);
    return NextResponse.json(
      { error: 'Internal server error' },
      { status: 500 }
    );
  }
}

Source: minds-ui/apps/api-service/app/api/v1/instances/[instanceId]/services/enable/route.ts:13.

Response and error branches

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

request.json()

Source: minds-ui/apps/api-service/app/api/v1/instances/[instanceId]/services/enable/route.ts:25.

new InvalidRequestError('services array required')

Source: minds-ui/apps/api-service/app/api/v1/instances/[instanceId]/services/enable/route.ts:29.

NextResponse.json(
        { error: 'Instance not found' },
        { status: 404 }
      )

Source: minds-ui/apps/api-service/app/api/v1/instances/[instanceId]/services/enable/route.ts:39.

NextResponse.json(result, { status: result.status === 'completed' ? 200 : 207 })

Source: minds-ui/apps/api-service/app/api/v1/instances/[instanceId]/services/enable/route.ts:71.

NextResponse.json(
        { error: error.message },
        { status: error.statusCode }
      )

Source: minds-ui/apps/api-service/app/api/v1/instances/[instanceId]/services/enable/route.ts:74.

NextResponse.json(
      { error: 'Internal server error' },
      { status: 500 }
    )

Source: minds-ui/apps/api-service/app/api/v1/instances/[instanceId]/services/enable/route.ts:81.

Service dependencies

  • minds-ui/apps/api-service/lib/services/auth-context.ts
  • minds-ui/apps/api-service/lib/services/hot-loading-service.ts
  • minds-ui/apps/api-service/types/errors.ts
  • minds-ui/apps/api-service/lib/db.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/instances/[instanceId]/services/enable/route.ts. SHA-256: 853b631e790341a05684cebc46ea2ac73b91922dd1d942c24532d56e343ba3f3.

On this page