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

# Send a turn

> Sends a prompt to Wren, or answers a question a parked run is waiting on, and streams the run back as server-sent events. The stream carries the same activity you would watch in the chat panel: Wren's reasoning steps, the tools it runs, the changes it applies, and its final message.

Accepts a personal access token only. Workspace API keys are not accepted on this endpoint.

> [!NOTE]
>
> This endpoint accepts a **personal access token** only. For modes, answering questions, continuing a conversation and handling the event stream, see the [Wren API guide](https://docs.poly.ai/wren/api.md).


## OpenAPI

````yaml POST /v1/studio-assistant/turn
openapi: 3.1.0
info:
  title: PolyAI Wren API
  version: 1.0.0
  description: Drive Wren from your own code, and read the recommendations it raises.
servers:
  - url: https://api.us.poly.ai
    description: US region
  - url: https://api.eu.poly.ai
    description: EU region
  - url: https://api.uk.poly.ai
    description: UK region
  - url: https://api.studio.poly.ai
    description: Studio region
security:
  - ApiKeyAuth: []
tags:
  - name: Turns
    description: Run Wren from your own code.
  - name: Recommendations
    description: Read the recommendations Wren raises on a project.
paths:
  /v1/studio-assistant/turn:
    post:
      tags:
        - Turns
      summary: Send a turn
      description: >-
        Sends a prompt to Wren, or answers a question a parked run is waiting
        on, and streams the run back as server-sent events. The stream carries
        the same activity you would watch in the chat panel: Wren's reasoning
        steps, the tools it runs, the changes it applies, and its final message.


        Accepts a personal access token only. Workspace API keys are not
        accepted on this endpoint.
      operationId: sendWrenTurn
      requestBody:
        required: true
        content:
          application/json:
            schema:
              oneOf:
                - $ref: '#/components/schemas/PromptTurn'
                - $ref: '#/components/schemas/InputResponseTurn'
            examples:
              prompt:
                summary: Send a prompt
                value:
                  prompt: >-
                    Add a topic for opening hours: 9-5 Monday to Friday, closed
                    weekends.
                  context:
                    accountId: acme-uk
                    projectId: acme-team-4
              answer:
                summary: Answer a question
                value:
                  type: input_response
                  sessionId: 7f3c1e02-4b6a-4d1f-9a55-2f9a0c1d33ab
                  requestId: toolu_01ABC
                  context:
                    accountId: acme-uk
                    projectId: acme-team-4
                  answer:
                    inputKind: plan
                    value:
                      approved: true
      responses:
        '200':
          description: >-
            The run, as a server-sent event stream. Each `data:` line is one
            JSON event carrying `type` and `sessionId`. Keep the connection open
            and read events as they arrive.
          content:
            text/event-stream:
              schema:
                type: string
              example: >+
                data: {"type":"message_delta","delta":"Looking
                at","sessionId":"7f3c1e02-4b6a-4d1f-9a55-2f9a0c1d33ab","depth":0}

        '400':
          description: >-
            The request body was invalid, or the project wasn't found. The
            message names the invalid field, or lists the projects you can use.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              example:
                error: 'Invalid request: context.projectId: Required'
        '401':
          description: >-
            Missing or invalid token, not a personal access token, or a token
            from another region.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              example:
                error: Invalid or non-PAT API key
        '403':
          description: >-
            You don't have access to that account or project, or the `sessionId`
            belongs to someone else.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              example:
                error: >-
                  You don't have permission to write to this conversation.
                  Shared conversations are read-only.
        '409':
          description: A run is already in progress on this session.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              example:
                error: >-
                  A run is already in progress. Please wait for it to finish or
                  cancel it before starting a new one.
        '500':
          description: Something went wrong on our side.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              example:
                error: Something went wrong. Please try again.
components:
  schemas:
    PromptTurn:
      type: object
      title: Send a prompt
      required:
        - prompt
        - context
      properties:
        prompt:
          type: string
          description: What you're asking Wren to do. Must contain some text.
        context:
          $ref: '#/components/schemas/TurnContext'
        sessionId:
          type: string
          format: uuid
          description: >-
            Continue an existing conversation. Omit to start a new one; the new
            conversation's ID is on every event in the stream.
    InputResponseTurn:
      type: object
      title: Answer a question
      required:
        - type
        - sessionId
        - requestId
        - context
        - answer
      properties:
        type:
          type: string
          enum:
            - input_response
        sessionId:
          type: string
          format: uuid
          description: The conversation the parked run belongs to.
        requestId:
          type: string
          description: >-
            The `requestId` from the `user_input_required` event you are
            answering.
        context:
          $ref: '#/components/schemas/TurnContext'
        answer:
          type: object
          required:
            - inputKind
            - value
          properties:
            inputKind:
              type: string
              enum:
                - question
                - plan
              description: Must match the event's `inputKind`.
            value:
              type: object
              description: >-
                For `question`: `{"answers": [{"selected": ["Option A"],
                "freeform": "optional"}]}`, one entry per question in the event.
                For `plan`: `{"approved": true}`, or `{"approved": false,
                "feedback": "what to change"}`.
    Error:
      type: object
      required:
        - error
      properties:
        error:
          type: string
          description: What went wrong.
        invalid:
          type: array
          items:
            type: string
          description: On a `400` from the list endpoint, the query parameters at fault.
        feature:
          type: string
          description: On a `403` for a feature that is not enabled, the feature's name.
    TurnContext:
      type: object
      required:
        - accountId
        - projectId
      properties:
        accountId:
          type: string
          description: Your account ID.
        projectId:
          type: string
          description: The project to work in.
        mode:
          type: string
          enum:
            - auto
            - interactive
            - headless
          default: auto
          description: >-
            `auto` runs the task start to finish. `interactive` makes Wren stop
            and wait at plan and question gates. `headless` never waits:
            anything needing an answer is recorded as a blocker in the final
            report. Set per turn, not per conversation.
        branchId:
          type: string
          description: >-
            Work on a specific Branch. Otherwise Wren creates one when it needs
            to.
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: X-API-KEY
      description: >-
        A personal access token, or for the recommendations endpoints a
        workspace API key. Include it in a header parameter called `X-API-KEY`.

````