# /api/v1/tenants/[id]/services/disable (management)

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

Source: https://docs.minds.sh/docs/api/platform/reference/management--api-v1-tenants-id-services-disable



This is the **management** service route. Its origin and authentication are described in [Platform API overview](/docs/api/platform) and [Authentication](/docs/api/platform/authentication). A path shared by another service is a different endpoint.

| Property                       | Contract                                                                       |
| ------------------------------ | ------------------------------------------------------------------------------ |
| Methods                        | POST                                                                           |
| Path                           | `/api/v1/tenants/[id]/services/disable`                                        |
| Path parameters                | `id`                                                                           |
| Query parameters read in route | None read directly; schema validation below may define additional fields       |
| Headers read in route          | No additional direct header reads; authentication helpers may read credentials |

## Authentication and access [#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.

## Method behavior [#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 [#post]

```typescript
export async function POST(
  request: NextRequest,
  { params }: { params: { tenantId: string } }
) {
  try {
    const authContext = await resolveAuthContext(request, {
      allowApiKey: true,
      allowSession: true,
    });

    const { tenantId } = params;

    const tenant = await prisma.tenant.findUnique({ where: { id: tenantId } });
    if (!tenant) {
      return NextResponse.json({ error: 'Tenant not found' }, { status: 404 });
    }

    await ensureTenantAccess(authContext, tenant.orgId, tenant.ownerId, {
      action: 'instance:manage',
      tenantId: tenant.id,
      resourceId: tenant.id,
      attributes: { operation: 'tenant-wide-service-disable' },
    });

    const body = await request.json();

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

    if (!body.instanceSelection || !body.instanceSelection.mode) {
      throw new InvalidRequestError('instanceSelection.mode required');
    }

    const result = await multiInstanceOrchestrator.disableServicesOnMultipleInstances(
      tenantId,
      body.services,
      body.instanceSelection,
      authContext.userId
    );

    return NextResponse.json(result);
  } catch (error) {
    if (error instanceof ApiError) {
      return NextResponse.json(
        { error: error.message },
        { status: error.statusCode }
      );
    }

    console.error('[API] Error disabling services on multiple instances:', error);
    return NextResponse.json({ error: 'Internal server error' }, { status: 500 });
  }
}
```

Source: `minds-ui/apps/api-service/app/api/v1/tenants/[id]/services/disable/route.ts:13`.

## Response and error branches [#response-and-error-branches]

Literal HTTP statuses in the route: 404, 500. Shared management error classes are defined in [Errors and responses](/docs/api/platform/errors).

```typescript
NextResponse.json({ error: 'Tenant not found' }, { status: 404 })
```

Source: `minds-ui/apps/api-service/app/api/v1/tenants/[id]/services/disable/route.ts:27`.

```typescript
request.json()
```

Source: `minds-ui/apps/api-service/app/api/v1/tenants/[id]/services/disable/route.ts:37`.

```typescript
new InvalidRequestError('services array required')
```

Source: `minds-ui/apps/api-service/app/api/v1/tenants/[id]/services/disable/route.ts:40`.

```typescript
new InvalidRequestError('instanceSelection.mode required')
```

Source: `minds-ui/apps/api-service/app/api/v1/tenants/[id]/services/disable/route.ts:44`.

```typescript
NextResponse.json(result)
```

Source: `minds-ui/apps/api-service/app/api/v1/tenants/[id]/services/disable/route.ts:54`.

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

Source: `minds-ui/apps/api-service/app/api/v1/tenants/[id]/services/disable/route.ts:57`.

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

Source: `minds-ui/apps/api-service/app/api/v1/tenants/[id]/services/disable/route.ts:64`.

## Service dependencies [#service-dependencies]

* `minds-ui/apps/api-service/lib/services/auth-context.ts`
* `minds-ui/apps/api-service/lib/services/multi-instance-orchestrator.ts`
* `minds-ui/apps/api-service/types/errors.ts`
* `minds-ui/apps/api-service/lib/db.ts`

## Evidence [#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]/services/disable/route.ts`. SHA-256: `675f412c7652faaaf2cb002082610677146fcbc904b2b24ab69d23ecf570b4ee`.
