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

# Connect proxy

> Routes the device's traffic through a SOCKS5 proxy supplied in the request body, replacing any existing connection. A smartIp option can be used to select an IP automatically; the legacy flat host/port/user/password fields remain supported.

Provide **exactly one** proxy definition: the `socks5` object, the deprecated flat `host`/`port`/`user`/`password` fields (all four required together), or a Mobilerun Connect `connect` reference (see below). Sending more than one fails validation.

## Mobilerun Connect proxies

Instead of passing credentials, reference a Mobilerun Connect proxy:

```json
{ "connect": { "id": "0d5a…" } }
```

fetches the credentials of an existing Connect proxy owned by the device's
owner (it must be `active` or `cancelling`), while

```json
{ "connect": { "country": "us" } }
```

provisions a rotating **residential** proxy in that country — or reuses the
one previously provisioned for this device when it is still active and in
the same country. Provisioning waits up to 60 s for the proxy to become
active. If payment is required first, the request fails with
`402 PAYMENT_REQUIRED` and a `paymentUrl` detail pointing to checkout.

With `smartIp: true`, the exit-IP precheck probes the proxy for up to \~45 s,
so a freshly provisioned proxy that is still being routed passes without
caller-side retries. If the precheck still fails, the error tells you why:

* `409 CONNECT_PROXY_NOT_ACTIVE` — the proxy is not (or no longer) serving
  traffic, e.g. still provisioning. Transient while provisioning: retry in a
  few seconds.
* A denial that keeps failing while the proxy is `active` usually means the
  organization is out of prepaid proxy data — but the gateway returns the
  same denial for short internal hiccups, so it surfaces as a generic error
  rather than a billing one. Check your proxy data balance if retries keep
  failing.

Pass exactly one of `id` or `country`, and don't combine `connect` with
`socks5` or the legacy flat fields. `smartIp` works with all variants.

A proxy provisioned via `country` stays with the device and is cancelled
automatically when the device is terminated. Proxies referenced by `id`
are never cancelled by this API.

With `smartIp: true`, the API geolocates the proxy's exit IP through the proxy itself and aligns the device to match — GPS location, time zone, locale, and (unless an eSIM is active) mobile carrier and network type.

<Warning>
  A smart IP failure leaves your existing proxy untouched, but a failure while connecting the new proxy can leave the device with no proxy at all. Check the proxy state before retrying.
</Warning>

<Note>
  On fleetd devices, an upstream switch on an already-proxied device applies live with no interruption, but the first time a device gets a proxy the device restarts to pick it up.
</Note>


## OpenAPI

````yaml /api-reference/phones/tools.yaml post /devices/{deviceId}/proxy
openapi: 3.1.0
info:
  title: Tools
  version: v1
servers:
  - description: Droidrun Cloud API
    url: https://api.mobilerun.ai/v1
security:
  - bearerAuth: []
paths:
  /devices/{deviceId}/proxy:
    post:
      tags:
        - Proxy
      summary: Connect proxy
      description: >-
        Routes the device's traffic through a SOCKS5 proxy supplied in the
        request body, replacing any existing connection. A smartIp option can be
        used to select an IP automatically; the legacy flat
        host/port/user/password fields remain supported.
      operationId: connect-proxy
      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
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ConnectProxyBody'
        required: true
      responses:
        '204':
          description: No Content
        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
            });

            await client.devices.proxy.connect('deviceId');
        - 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
            )
            client.devices.proxy.connect(
                device_id="deviceId",
            )
components:
  schemas:
    ConnectProxyBody:
      additionalProperties: false
      properties:
        $schema:
          description: A URL to the JSON Schema for this object.
          examples:
            - https://example.com/schemas/ConnectProxyBody.json
          format: uri
          readOnly: true
          type: string
        connect:
          $ref: '#/components/schemas/Ref'
          description: >-
            Mobilerun Connect proxy — pass exactly one of id (use an existing
            proxy's credentials) or country (provision or reuse a rotating
            residential proxy for the device).
        host:
          deprecated: true
          format: hostname
          maxLength: 255
          type: string
        name:
          description: Proxy name
          maxLength: 255
          type: string
        password:
          deprecated: true
          maxLength: 255
          type: string
          writeOnly: true
        port:
          deprecated: true
          format: int64
          maximum: 65535
          minimum: 1
          type: integer
        smartIp:
          type: boolean
        socks5:
          $ref: '#/components/schemas/ConnectSOCKS5Config'
          description: SOCKS5 proxy configuration (required for socks5).
        user:
          deprecated: true
          maxLength: 255
          type: string
      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
    Ref:
      additionalProperties: false
      properties:
        country:
          description: >-
            ISO 3166-1 alpha-2 country code; provisions (or reuses) a rotating
            residential Mobilerun Connect proxy for the device.
          pattern: ^[a-zA-Z]{2}$
          type: string
        id:
          description: >-
            Existing Mobilerun Connect proxy id; its credentials are fetched
            server-side.
          format: uuid
          type: string
      type: object
    ConnectSOCKS5Config:
      additionalProperties: false
      properties:
        host:
          format: hostname
          maxLength: 255
          type: string
        password:
          maxLength: 255
          type: string
          writeOnly: true
        port:
          format: int64
          maximum: 65535
          minimum: 1
          type: integer
        user:
          maxLength: 255
          type: string
      required:
        - host
        - port
      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
  securitySchemes:
    bearerAuth:
      bearerFormat: Opaque
      description: Bearer token via Authorization header
      scheme: bearer
      type: http

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.