> ## Documentation Index
> Fetch the complete documentation index at: https://docs.avidoai.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Set active organization for current session

> Switches the active organisation on the authenticated session. Called in-process via `auth.api.setActiveOrganization` so server-to-server requests are not subject to Better Auth's `Origin`-header CSRF check. Better Auth rotates the active-org cookie; the rotated `Set-Cookie` headers are forwarded on the response so the browser's cookie jar is updated atomically with the 201 reply.



## OpenAPI

````yaml https://app.stainless.com/api/spec/documented/avido/openapi.documented.yml post /v0/auth/organizations/set-active
openapi: 3.1.1
info:
  title: Avido API
  description: >-
    Avido's API for LLM usage events, tool calls, trace management, webhook
    validation, and more. See each endpoint's request/response schema for
    details.
  version: 0.1.0
  contact:
    name: Avido Support
    email: support@avidoai.com
    url: https://avidoai.com/support
servers:
  - url: https://api.avidoai.com
    description: Production API
security:
  - ApiKey: []
    ApplicationId: []
paths:
  /v0/auth/organizations/set-active:
    post:
      tags:
        - Authentication
      summary: Set active organization for current session
      description: >-
        Switches the active organisation on the authenticated session. Called
        in-process via `auth.api.setActiveOrganization` so server-to-server
        requests are not subject to Better Auth's `Origin`-header CSRF check.
        Better Auth rotates the active-org cookie; the rotated `Set-Cookie`
        headers are forwarded on the response so the browser's cookie jar is
        updated atomically with the 201 reply.
      operationId: setActiveAuthOrganization
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/SetActiveOrganizationRequest'
      responses:
        '201':
          description: Successfully switched active organization
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SetActiveOrganizationResponse'
        '401':
          description: No valid session present
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '404':
          description: >-
            Organisation not found, or caller is not a member of the requested
            organisation. Both cases return an identical response to prevent
            cross-tenant existence enumeration (APP-2973).
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '422':
          description: invalid input
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ValidationErrorResponse'
        '500':
          description: internal server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
      security: []
components:
  schemas:
    SetActiveOrganizationRequest:
      type: object
      properties:
        organizationId:
          type: string
          minLength: 1
          maxLength: 256
      required:
        - organizationId
      additionalProperties: false
      title: SetActiveOrganizationRequest
      description: >-
        Id of the organization to set as the active organisation on the
        authenticated session.
    SetActiveOrganizationResponse:
      type: object
      properties:
        data:
          $ref: '#/components/schemas/Organization'
      required:
        - data
      additionalProperties: false
      title: SetActiveOrganizationResponse
      description: >-
        The organisation that was set as the active organisation on the
        authenticated session.
    ErrorResponse:
      type: object
      properties:
        message:
          type: string
          description: A human-readable error message explaining the error.
          example: Resource not found
      required:
        - message
      additionalProperties: false
      title: ErrorResponse
      description: Standard error format for failed API operations.
    ValidationErrorResponse:
      type: object
      properties:
        message:
          type: string
          description: A human-readable error message indicating what went wrong.
          example: Invalid request data
        issues:
          type: array
          items:
            type: object
            properties:
              code:
                type: string
              message:
                type: string
              path:
                type: array
                items:
                  type: string
            required:
              - code
              - message
              - path
            additionalProperties: false
          description: Array of detailed validation error objects.
          example:
            - code: invalid_string
              message: Invalid UUID
              path:
                - id
      required:
        - message
        - issues
      additionalProperties: false
      title: ValidationErrorResponse
      description: Details about validation errors in incoming requests.
    Organization:
      type: object
      properties:
        id:
          type: string
        name:
          type: string
        allowDomainAutoJoin:
          type: boolean
        domain:
          type: string
        slug:
          type: string
        logo:
          anyOf:
            - type: string
            - type: 'null'
      required:
        - id
        - name
        - allowDomainAutoJoin
      additionalProperties: false
      title: Organization
      description: >-
        A Better Auth organisation the authenticated user belongs to, normalised
        to the public Avido shape (Prisma-nullable slug/domain surfaced as
        absent rather than null).
  securitySchemes:
    ApiKey:
      type: apiKey
      in: header
      name: x-api-key
      description: Your unique Avido API key
    ApplicationId:
      type: apiKey
      in: header
      name: x-application-id
      description: Your unique Avido Application ID

````