# Proxies

## 获取所有代理

<mark style="color:blue;">`GET`</mark> `/proxies`

获取 Clash 中所有的代理

{% tabs %}
{% tab title="200
代理类型: Direct | Reject | Selector | Shadowsocks | Socks5 | URLTest

类型为 Selector 时有 all 和 now 两个字段，分别代表所含有的代理以及现在选中的代理

类型未 URLTest 时 now 字段为现在最快的代理名字
" %}

```javascript
{
    "proxies": {
        "DIRECT": {
            "type": "Direct"
        },
        "GLOBAL": {
            "all": [
                "Proxy",
                "auto",
                "🇭🇰"
            ],
            "now": "Proxy",
            "type": "Selector"
        },
        "Proxy": {
            "all": [
                "auto",
                "🇭🇰"
            ],
            "now": "auto",
            "type": "Selector"
        },
        "REJECT": {
            "type": "Reject"
        },
        "auto": {
            "now": "🇭🇰",
            "type": "URLTest"
        },
        "🇭🇰": {
            "type": "Shadowsocks"
        }
    }
}
```

{% endtab %}
{% endtabs %}

## &#x20;获取单个代理信息

<mark style="color:blue;">`GET`</mark> `/proxies/:name`

&#x20;获取 Clash 中单个代理的信息

#### Path Parameters

| Name | Type   | Description |
| ---- | ------ | ----------- |
| name | string | 代理名 (大小写敏感) |

{% tabs %}
{% tab title="200
代理类型: Direct | Reject | Selector | Shadowsocks | Socks5 | URLTest

类型为 Selector 时有 all 和 now 两个字段，分别代表所含有的代理以及现在选中的代理

类型未 URLTest 时 now 字段为现在最快的代理名字
" %}

```javascript
{
    "all": [
        "auto",
        "🇭🇰"
    ],
    "now": "auto",
    "type": "Selector"
}
```

{% endtab %}

{% tab title="404 " %}

```javascript
{
    "error": "Proxy not found"
}
```

{% endtab %}
{% endtabs %}

## &#x20;获取单个代理的延迟

<mark style="color:blue;">`GET`</mark> `/proxies/:name/delay`

获取 Clash 中单个代理的延迟

#### Path Parameters

| Name | Type   | Description |
| ---- | ------ | ----------- |
| name | string | 代理名 (大小写敏感) |

#### Query Parameters

| Name    | Type   | Description |
| ------- | ------ | ----------- |
| timeout | number | 超时时间 (ms)   |
| url     | string | 测试代理的目标网址   |

{% tabs %}
{% tab title="200
正常返回
" %}

```javascript
{
    "delay": 200
}
```

{% endtab %}

{% tab title="400
请求格式错误
" %}

```javascript
{
    "error": "Format error"
}
```

{% endtab %}

{% tab title="404
代理不存在
" %}

```javascript
{
    "error": "Proxy not found"
}
```

{% endtab %}

{% tab title="408
代理请求超时
" %}

```javascript
{
    "error": "Proxy delay test timeout"
}
```

{% endtab %}
{% endtabs %}

## &#x20;切换 Selector 中选中的代理

<mark style="color:orange;">`PUT`</mark> `/proxies/:name`

当前接口只支持切换 Selector 中的代理

#### Path Parameters

| Name | Type   | Description  |
| ---- | ------ | ------------ |
| name | string | 代理名称 (大小写敏感) |

#### Request Body

| Name | Type   | Description |
| ---- | ------ | ----------- |
| name | string | 要切换的代理名字    |

{% tabs %}
{% tab title="204
切换成功
" %}

```
```

{% endtab %}

{% tab title="400 " %}
{% tabs %}
{% tab title="请求格式错误" %}
{% code title="请求格式错误" %}

```javascript
{
    "error": "Format error"
}
```

{% endcode %}
{% endtab %}

{% tab title="请求代理类型错误" %}
{% code title="请求代理类型错误" %}

```javascript
{
    "error": "Proxy can't update"
}
```

{% endcode %}
{% endtab %}
{% endtabs %}
{% endtab %}

{% tab title="404
代理不存在
" %}

```javascript
{
    "error": "Proxy not found"
}
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://clash.gitbook.io/doc/restful-api/proxies.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
