# /api/chat/context (dashboard)

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

Source: https://docs.minds.sh/docs/api/platform/reference/dashboard--api-chat-context



This is the **dashboard** 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                        | GET                                                                            |
| Path                           | `/api/chat/context`                                                            |
| Path parameters                | None                                                                           |
| 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]

Dashboard session cookie through @repo/auth/server. Some auth-summary routes can redirect to sign-in; inspect the status branches below.

## 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.

### GET [#get]

```typescript
export async function GET() {
  const session = await getSession();
  if (!session) {
    return NextResponse.json(
      {
        error: {
          code: 'UNAUTHENTICATED',
          message: 'Sign in at auth.l1fe.ai before using Operator chat.',
        },
      },
      { status: 401, headers: noStoreHeaders() }
    );
  }

  try {
    const cookieStore = await cookies();
    const context = await buildOperatorContext({
      accessToken: session.accessToken,
      tokenOrgId: session.user.orgId,
      tokenTenantId: session.user.tenantId,
      activeTenantId: cookieStore.get(ACTIVE_TENANT_COOKIE)?.value,
      activeServiceId: cookieStore.get(ACTIVE_SERVICE_COOKIE)?.value,
      userName: session.user.name ?? null,
      userEmail: session.user.email ?? null,
    });
    return NextResponse.json(context, { headers: noStoreHeaders() });
  } catch (error) {
    console.error('Operator context request failed:', error);
    return NextResponse.json(
      {
        error: {
          code: 'CONTEXT_UNAVAILABLE',
          message:
            error instanceof Error
              ? error.message
              : 'Operator context is unavailable.',
        },
      },
      { status: 500, headers: noStoreHeaders() }
    );
  }
}
```

Source: `minds-ui/apps/app/app/api/chat/context/route.ts:24`.

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

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

```typescript
NextResponse.json(
      {
        error: {
          code: 'UNAUTHENTICATED',
          message: 'Sign in at auth.l1fe.ai before using Operator chat.',
        },
      },
      { status: 401, headers: noStoreHeaders() }
    )
```

Source: `minds-ui/apps/app/app/api/chat/context/route.ts:27`.

```typescript
NextResponse.json(context, { headers: noStoreHeaders() })
```

Source: `minds-ui/apps/app/app/api/chat/context/route.ts:49`.

```typescript
NextResponse.json(
      {
        error: {
          code: 'CONTEXT_UNAVAILABLE',
          message:
            error instanceof Error
              ? error.message
              : 'Operator context is unavailable.',
        },
      },
      { status: 500, headers: noStoreHeaders() }
    )
```

Source: `minds-ui/apps/app/app/api/chat/context/route.ts:52`.

## Service dependencies [#service-dependencies]

* `minds-ui/apps/app/lib/chat/operator-context.ts`
* `minds-ui/apps/app/lib/organizations.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/app/app/api/chat/context/route.ts`. SHA-256: `e4b97b9711096a86bae4e6ba788a85a0e44d539c848e2e4665ef5507eaebd6bd`.
