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

# UI state

> Returns the current accessibility UI state of the device as a structured tree of on-screen elements. An optional filter query reduces the result to interactive elements.



## OpenAPI

````yaml /api-reference/phones/tools.yaml get /devices/{deviceId}/ui-state
openapi: 3.1.0
info:
  title: Tools
  version: v1
servers:
  - url: https://api.mobilerun.ai
    description: Droidrun Cloud API
security:
  - bearerAuth: []
paths:
  /devices/{deviceId}/ui-state:
    get:
      tags:
        - Navigation
      summary: UI state
      description: >-
        Returns the current accessibility UI state of the device as a structured
        tree of on-screen elements. An optional filter query reduces the result
        to interactive elements.
      operationId: ui-state
      parameters:
        - in: path
          name: deviceId
          required: true
          schema:
            type: string
        - in: header
          name: X-Device-Display-ID
          schema:
            default: 0
            format: int64
            minimum: 0
            type: integer
        - explode: false
          in: query
          name: filter
          schema:
            default: false
            type: boolean
      responses:
        '200':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AndroidState'
          description: OK
        default:
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/ErrorModel'
          description: Error
      security:
        - bearerAuth: []
      x-codeSamples:
        - lang: JavaScript
          source: |-
            import Mobilerun from '@mobilerun/sdk';

            const client = new Mobilerun({
              apiKey: process.env['MOBILERUN_CLOUD_API_KEY'], // This is the default and can be omitted
            });

            const response = await client.devices.state.ui('deviceId');

            console.log(response.a11y_tree);
        - lang: Python
          source: |-
            import os
            from mobilerun_sdk import Mobilerun

            client = Mobilerun(
                api_key=os.environ.get("MOBILERUN_CLOUD_API_KEY"),  # This is the default and can be omitted
            )
            response = client.devices.state.ui(
                device_id="deviceId",
            )
            print(response.a11y_tree)
        - lang: Go
          source: "package main\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\n\t\"github.com/stainless-sdks/droidrun-cloud-go\"\n\t\"github.com/stainless-sdks/droidrun-cloud-go/option\"\n)\n\nfunc main() {\n\tclient := mobileruncloud.NewClient(\n\t\toption.WithAPIKey(\"My API Key\"),\n\t)\n\tresponse, err := client.Devices.State.Ui(\n\t\tcontext.TODO(),\n\t\t\"deviceId\",\n\t\tmobileruncloud.DeviceStateUiParams{},\n\t)\n\tif err != nil {\n\t\tpanic(err.Error())\n\t}\n\tfmt.Printf(\"%+v\\n\", response.A11yTree)\n}\n"
        - lang: CLI
          source: |-
            mobilerun-cloud devices:state ui \
              --api-key 'My API Key' \
              --device-id deviceId
components:
  schemas:
    AndroidState:
      additionalProperties: false
      properties:
        $schema:
          description: A URL to the JSON Schema for this object.
          examples:
            - https://example.com/schemas/AndroidState.json
          format: uri
          readOnly: true
          type: string
        a11y_tree:
          $ref: '#/components/schemas/A11YNode'
        device_context:
          $ref: '#/components/schemas/DeviceContext'
        ime_tree:
          $ref: '#/components/schemas/A11YNode'
        phone_state:
          $ref: '#/components/schemas/PhoneState'
      required:
        - a11y_tree
        - ime_tree
        - phone_state
        - device_context
      type: object
    ErrorModel:
      additionalProperties: false
      properties:
        $schema:
          description: A URL to the JSON Schema for this object.
          examples:
            - https://example.com/schemas/ErrorModel.json
          format: uri
          readOnly: true
          type: string
        detail:
          description: >-
            A human-readable explanation specific to this occurrence of the
            problem.
          examples:
            - Property foo is required but is missing.
          type: string
        errors:
          description: Optional list of individual error details
          items:
            $ref: '#/components/schemas/ErrorDetail'
          type:
            - array
            - 'null'
        instance:
          description: >-
            A URI reference that identifies the specific occurrence of the
            problem.
          examples:
            - https://example.com/error-log/abc123
          format: uri
          type: string
        status:
          description: HTTP status code
          examples:
            - 400
          format: int64
          type: integer
        title:
          description: >-
            A short, human-readable summary of the problem type. This value
            should not change between occurrences of the error.
          examples:
            - Bad Request
          type: string
        type:
          default: about:blank
          description: A URI reference to human-readable documentation for the error.
          examples:
            - https://example.com/errors/example
          format: uri
          type: string
      type: object
    A11YNode:
      additionalProperties: false
      properties:
        boundsInScreen:
          $ref: '#/components/schemas/A11YBounds'
        children:
          items:
            $ref: '#/components/schemas/A11YNode'
          type:
            - array
            - 'null'
        className:
          type: string
        contentDescription:
          type: string
        isCheckable:
          type: boolean
        isChecked:
          type: boolean
        isClickable:
          type: boolean
        isEnabled:
          type: boolean
        isFocusable:
          type: boolean
        isFocused:
          type: boolean
        isLongClickable:
          type: boolean
        isPassword:
          type: boolean
        isScrollable:
          type: boolean
        isSelected:
          type: boolean
        packageName:
          type: string
        resourceId:
          type: string
        text:
          type: string
      required:
        - boundsInScreen
        - className
        - resourceId
        - text
        - contentDescription
        - packageName
        - isCheckable
        - isChecked
        - isClickable
        - isEnabled
        - isFocusable
        - isFocused
        - isScrollable
        - isLongClickable
        - isPassword
        - isSelected
        - children
      type: object
    DeviceContext:
      additionalProperties: false
      properties:
        display_metrics:
          $ref: '#/components/schemas/DisplayMetrics'
        filtering_params:
          $ref: '#/components/schemas/FilteringParams'
        screen_bounds:
          $ref: '#/components/schemas/Rect'
      required:
        - screen_bounds
        - filtering_params
        - display_metrics
      type: object
    PhoneState:
      additionalProperties: false
      properties:
        activityName:
          type: string
        currentApp:
          type: string
        focusedElement:
          $ref: '#/components/schemas/PhoneStateFocusedElementStruct'
        isEditable:
          type: boolean
        keyboardVisible:
          type: boolean
        packageName:
          type: string
      required:
        - keyboardVisible
        - isEditable
      type: object
    ErrorDetail:
      additionalProperties: false
      properties:
        location:
          description: >-
            Where the error occurred, e.g. 'body.items[3].tags' or
            'path.thing-id'
          type: string
        message:
          description: Error message text
          type: string
        value:
          description: The value at the given location
      type: object
    A11YBounds:
      additionalProperties: false
      properties:
        bottom:
          format: int64
          type: integer
        left:
          format: int64
          type: integer
        right:
          format: int64
          type: integer
        top:
          format: int64
          type: integer
      required:
        - left
        - top
        - right
        - bottom
      type: object
    DisplayMetrics:
      additionalProperties: false
      properties:
        density:
          format: double
          type: number
        densityDpi:
          format: int64
          type: integer
        heightPixels:
          format: int64
          type: integer
        scaledDensity:
          format: double
          type: number
        widthPixels:
          format: int64
          type: integer
      required:
        - density
        - densityDpi
        - scaledDensity
        - widthPixels
        - heightPixels
      type: object
    FilteringParams:
      additionalProperties: false
      properties:
        min_element_size:
          format: int64
          type: integer
        overlay_offset:
          format: int64
          type: integer
      required:
        - min_element_size
        - overlay_offset
      type: object
    Rect:
      additionalProperties: false
      properties:
        height:
          format: int64
          type: integer
        width:
          format: int64
          type: integer
      required:
        - width
        - height
      type: object
    PhoneStateFocusedElementStruct:
      additionalProperties: false
      properties:
        className:
          type: string
        resourceId:
          type: string
        text:
          type: string
      type: object
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: Opaque
      description: Bearer token via Authorization header

````