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

# Definir Proxy

> Define ou remove o proxy individual da instância

**Auth:** `TokenAccount` ou `TokenInstance` • **Rate-limit:** `Global` (100/min) • **Idempotente:** sim

## Descrição

Define proxy HTTP, HTTPS ou SOCKS5 específico da instância. A configuração só toma efeito após `/reconnect` ou novo `/connect`.

## Exemplos

### SOCKS5 autenticado

Configura um proxy SOCKS5 na porta `1080` com usuário e senha. A senha é encriptada at-rest com AES-256-GCM e nunca volta em plaintext na resposta.

<CodeGroup>
  ```bash cURL theme={null}
  curl -X POST "https://ryzeapi.cloud/api/instance/proxy/minha-instancia" \
    -H "token: $Token_Instance" \
    -H "Content-Type: application/json" \
    -d '{
      "enabled": true,
      "host": "proxy.exemplo.com",
      "port": "1080",
      "protocol": "socks5",
      "username": "user1",
      "password": "secret"
    }'
  ```

  ```javascript JavaScript theme={null}
  await fetch("https://ryzeapi.cloud/api/instance/proxy/minha-instancia", {
    method: "POST",
    headers: {
      "token":        process.env.Token_Instance,
      "Content-Type": "application/json"
    },
    body: JSON.stringify({
      enabled:  true,
      host:     "proxy.exemplo.com",
      port:     "1080",
      protocol: "socks5",
      username: "user1",
      password: "secret"
    })
  });
  ```

  ```python Python theme={null}
  import os, requests

  requests.post(
      "https://ryzeapi.cloud/api/instance/proxy/minha-instancia",
      headers={
          "token":        os.environ["Token_Instance"],
          "Content-Type": "application/json"
      },
      json={
          "enabled":  True,
          "host":     "proxy.exemplo.com",
          "port":     "1080",
          "protocol": "socks5",
          "username": "user1",
          "password": "secret"
      }
  )
  ```

  ```go Go theme={null}
  package main

  import (
      "net/http"
      "os"
      "strings"
  )

  func main() {
      body := strings.NewReader(`{
          "enabled":  true,
          "host":     "proxy.exemplo.com",
          "port":     "1080",
          "protocol": "socks5",
          "username": "user1",
          "password": "secret"
      }`)
      req, _ := http.NewRequest("POST", "https://ryzeapi.cloud/api/instance/proxy/minha-instancia", body)
      req.Header.Set("token", os.Getenv("Token_Instance"))
      req.Header.Set("Content-Type", "application/json")
      http.DefaultClient.Do(req)
  }
  ```
</CodeGroup>

### HTTP sem auth

Aponta para um proxy HTTP interno (`10.0.0.5:3128`) sem credenciais, cenário comum em redes corporativas com auth-by-IP ou proxy aberto.

<CodeGroup>
  ```bash cURL theme={null}
  curl -X POST "https://ryzeapi.cloud/api/instance/proxy/minha-instancia" \
    -H "token: $Token_Instance" \
    -H "Content-Type: application/json" \
    -d '{"enabled":true,"host":"10.0.0.5","port":"3128","protocol":"http"}'
  ```

  ```javascript JavaScript theme={null}
  await fetch("https://ryzeapi.cloud/api/instance/proxy/minha-instancia", {
    method: "POST",
    headers: {
      "token":        process.env.Token_Instance,
      "Content-Type": "application/json"
    },
    body: JSON.stringify({
      enabled:  true,
      host:     "10.0.0.5",
      port:     "3128",
      protocol: "http"
    })
  });
  ```

  ```python Python theme={null}
  import os, requests

  requests.post(
      "https://ryzeapi.cloud/api/instance/proxy/minha-instancia",
      headers={
          "token":        os.environ["Token_Instance"],
          "Content-Type": "application/json"
      },
      json={
          "enabled":  True,
          "host":     "10.0.0.5",
          "port":     "3128",
          "protocol": "http"
      }
  )
  ```

  ```go Go theme={null}
  package main

  import (
      "net/http"
      "os"
      "strings"
  )

  func main() {
      body := strings.NewReader(`{"enabled":true,"host":"10.0.0.5","port":"3128","protocol":"http"}`)
      req, _ := http.NewRequest("POST", "https://ryzeapi.cloud/api/instance/proxy/minha-instancia", body)
      req.Header.Set("token", os.Getenv("Token_Instance"))
      req.Header.Set("Content-Type", "application/json")
      http.DefaultClient.Do(req)
  }
  ```
</CodeGroup>

### Desabilitar

Envia apenas `enabled: false` para remover o proxy individual da instância. Ela volta a usar o proxy global do deploy (se houver) ou conexão direta na próxima reconexão.

<CodeGroup>
  ```bash cURL theme={null}
  curl -X POST "https://ryzeapi.cloud/api/instance/proxy/minha-instancia" \
    -H "token: $Token_Instance" \
    -H "Content-Type: application/json" \
    -d '{"enabled":false}'
  ```

  ```javascript JavaScript theme={null}
  await fetch("https://ryzeapi.cloud/api/instance/proxy/minha-instancia", {
    method: "POST",
    headers: {
      "token":        process.env.Token_Instance,
      "Content-Type": "application/json"
    },
    body: JSON.stringify({ enabled: false })
  });
  ```

  ```python Python theme={null}
  import os, requests

  requests.post(
      "https://ryzeapi.cloud/api/instance/proxy/minha-instancia",
      headers={
          "token":        os.environ["Token_Instance"],
          "Content-Type": "application/json"
      },
      json={"enabled": False}
  )
  ```

  ```go Go theme={null}
  package main

  import (
      "net/http"
      "os"
      "strings"
  )

  func main() {
      body := strings.NewReader(`{"enabled":false}`)
      req, _ := http.NewRequest("POST", "https://ryzeapi.cloud/api/instance/proxy/minha-instancia", body)
      req.Header.Set("token", os.Getenv("Token_Instance"))
      req.Header.Set("Content-Type", "application/json")
      http.DefaultClient.Do(req)
  }
  ```
</CodeGroup>

## Resposta de sucesso

```json 200 OK theme={null}
{
  "success": true,
  "message": "Proxy configuration updated successfully",
  "proxy": {
    "enabled": true,
    "host": "proxy.exemplo.com",
    "port": "1080",
    "protocol": "socks5",
    "username": "user1",
    "password": ""
  }
}
```

<Note>
  O `password` aparece como string vazia (`""`) na resposta, o servidor nunca devolve a senha em plaintext.
</Note>

## Path parameters

<ParamField path="instance" type="string" required>
  Nome da instância.
</ParamField>

## Headers

<ParamField header="token" type="string" required>
  TokenAccount ou TokenInstance.
</ParamField>

<ParamField header="Content-Type" type="string" required>
  `application/json`.
</ParamField>

## Request body

<ParamField body="enabled" type="boolean" required>
  Ativa/desativa o proxy de instância.
</ParamField>

<ParamField body="host" type="string">
  IP ou hostname. **Obrigatório** se `enabled=true`.
</ParamField>

<ParamField body="port" type="string">
  Porta como string (`"1080"`, `"8080"`). **Obrigatório** se `enabled=true`.
</ParamField>

<ParamField body="protocol" type="string">
  `"http"`, `"https"` ou `"socks5"`. **Obrigatório** se `enabled=true`.
</ParamField>

<ParamField body="username" type="string">
  Usuário (opcional).
</ParamField>

<ParamField body="password" type="string">
  Senha (opcional, encriptada at-rest).
</ParamField>

## Regras

* `enabled=true` exige `host`, `port` e `protocol`.
* `protocol` deve ser `http`, `https` ou `socks5`.
* `username` / `password` são opcionais (proxy aberto ou auth-by-IP).
* `enabled=false` faz a instância voltar a usar o proxy padrão do deploy (se houver).
* A senha é **encriptada at-rest** (AES-256-GCM) e **redigida** na resposta.

## Notas

<Note>
  O proxy individual da instância tem **prioridade** sobre o proxy global do deploy. Se `enabled=false`, a instância usa o proxy global (se houver) ou conexão direta.
</Note>

<Warning>
  Mudanças no proxy **não reconectam automaticamente**, chame [`reconnect`](/pt/api/instance/reconnect) para aplicar.
</Warning>

## Erros

| HTTP | `error.message`                                | Quando                         |
| :--: | ---------------------------------------------- | ------------------------------ |
|  400 | `Invalid request body`                         | JSON malformado.               |
|  400 | `Host is required when proxy is enabled`       | `enabled=true` sem `host`.     |
|  400 | `Port is required when proxy is enabled`       | `enabled=true` sem `port`.     |
|  400 | `Protocol is required when proxy is enabled`   | `enabled=true` sem `protocol`. |
|  400 | `Protocol must be one of: http, https, socks5` | `protocol` fora do enum.       |
|  401 | `Invalid token`                                | Token ausente ou inválido.     |
|  404 | `Instance not found`                           | Nome não existe.               |
|  429 | `Rate limit exceeded. Try again later.`        | Mais de 100 req/min.           |
|  500 | `Failed to update proxy configuration`         | Erro de banco.                 |

```json theme={null}
{
  "success": false,
  "error": {
    "message": "Protocol must be one of: http, https, socks5"
  }
}
```
