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

> ## Agent Instructions
> Setting OneCLI up for your person? Follow https://onecli.sh/docs/quickstart.md. Never ask for or accept a key, token or password in the chat: OneCLI needs none.
> No OneCLI credential? Run `onecli connect`, or follow https://onecli.sh/auth.md. A person approves every new agent in their browser.
> Already connected? `onecli status`, `onecli items` and `onecli check <METHOD> <URL>` tell you what you can use. Full guide: https://onecli.sh/skill.md
> Search these docs over MCP at https://onecli.sh/docs/mcp. Report a wrong or unclear page with its `submit_feedback` tool.

# Call an API through the gateway's address

> Send a call through the OneCLI gateway by its address when a client cannot use a proxy: the URL shape, the header, examples and the answers you can get.

The address form sends a call through the gateway by its address. Use it for a client that you cannot point at a proxy. You put the real API's host in the path, and the gateway attaches the key from the agent's vault.

It needs no proxy settings, no certificate and no install.

## When to use it

Most clients are simpler to connect through the proxy settings. See [Connect coding agents](https://onecli.sh/docs/guides/coding-agents.md). Use the address form for these:

* A client that has no proxy setting.
* `wget` and Python's `urllib` on OneCLI Cloud. Neither can talk to an HTTPS proxy.
* Node's `http` and `https` modules, and clients built on them such as axios and got, in a sandbox that allows hosts by name. Node gives an HTTPS proxy no server name ([nodejs/node#66718](https://github.com/nodejs/node/issues/66718)), so such a sandbox drops the connection. Node `fetch` is not affected.

## Before you start

* An agent connected to a vault. See [Connect coding agents](https://onecli.sh/docs/guides/coding-agents.md).
* The agent's own credential in `ONECLI_AGENT_CREDENTIAL`. Connecting writes it to `agent.env`.
* An item in the vault for the host you call. The examples use the **Test key** for `httpbin.org`.

## Build the address

Put `https://gateway.onecli.sh/r/` in front of the real API's host and path:

```text theme={null}
https://gateway.onecli.sh/r/<host>/<path>
```

| Part | What to put there |
| - | - |
| `<host>` | The real API's host, such as `httpbin.org`. It may carry a port, such as `api.example.com:8443`. |
| `<path>` | The path you would call on the real API. The gateway keeps the query string. |

Leave the scheme out. The gateway always calls the real host over `https://`.

On a self-hosted gateway, the form is the same `/r/<host>/<path>` path on your gateway's own address and port.

## Send the agent credential

Send the agent's credential as a bearer token, and no key for the real API:

```text theme={null}
Authorization: Bearer $ONECLI_AGENT_CREDENTIAL
```

This is the only header the gateway reads the credential from. It takes the credential off the request, so the real API does not see it.

After that, the gateway treats the call like a proxied one. It runs the same checks, rules and approvals, attaches the key, and writes the call to the activity log.

## Make a call

`httpbin.org/bearer` answers `401` to a request with no token. A `200` shows that the gateway attached the **Test key**.

> [tab] curl
>
> ```bash theme={null}
> curl -s -o /dev/null -w "%{http_code}\n" \
>   -H "Authorization: Bearer $ONECLI_AGENT_CREDENTIAL" \
>   https://gateway.onecli.sh/r/httpbin.org/bearer
> ```
>
> ```text theme={null}
> 200
> ```

> [tab] Node fetch
>
> ```javascript theme={null}
> const response = await fetch("https://gateway.onecli.sh/r/httpbin.org/bearer", {
>   headers: {
>     Authorization: `Bearer ${process.env.ONECLI_AGENT_CREDENTIAL}`,
>   },
> });
>
> if (!response.ok) {
>   // The gateway sets this header on answers it made itself.
>   const decision = response.headers.get("x-onecli-decision");
>   throw new Error(`Call failed: ${response.status} ${decision ?? ""}`);
> }
>
> console.log(response.status);
> ```
>
> ```text theme={null}
> 200
> ```

## If the proxy settings are on

Connecting an agent sets `HTTPS_PROXY` in its environment. A client that reads it sends the address-form call through the proxy as well. `curl` and Node `fetch` still get their answer that way. `wget`, Python's `urllib` and Node's `http` and `https` modules can fail, for the reasons above.

Add the gateway's host to `NO_PROXY`, so that the call goes straight to the gateway:

```bash theme={null}
export NO_PROXY="$NO_PROXY,gateway.onecli.sh"
export no_proxy="$NO_PROXY"
```

Calls to every other host still go through the proxy.

## Answers from the gateway

The gateway sets an `X-Onecli-Decision` header on every answer it makes itself. An answer from the real API does not have it.

| Status | `X-Onecli-Decision` | What it means | What to do |
| - | - | - | - |
| `401` | `unauthenticated` | The call has no agent credential in `Authorization: Bearer`, or the agent has ended: its lifetime ran out, or it was disconnected. | Send the header shown above. If you did, the agent has ended: make a new one. |
| `403` | `no_credential` | The agent's vault has no item for that host. The error is `credential_not_found`, and the body has a `secret_url`. | Open the `secret_url` to add an item, then call again. |

A call with no credential gets this answer:

```json theme={null}
{
  "error": "unauthenticated",
  "message": "Send the agent credential as Authorization: Bearer oc_agent_..."
}
```

A rule or a permission can also refuse or hold an address-form call, as it can a proxied one. Every code is in [Gateway errors](https://onecli.sh/docs/api-reference/gateway-errors.md).

## Redirects, pages and cookies

The gateway changes three headers on the way back:

* It rewrites `Location`, so a redirect still goes through the gateway.
* It rewrites `Link`, so a next page still goes through the gateway.
* It drops `Set-Cookie`.

## What the address form does not do

The gateway does not read an `x-api-key` header as the credential. A call that sends the agent credential that way gets a `401`.

So the rule for a client is:

* A client that sends its key as `Authorization: Bearer` can use the address form.
* A client that sends its key as `x-api-key` cannot. Connect it through the proxy settings instead.

## Next steps

* [Connect coding agents](https://onecli.sh/docs/guides/coding-agents.md) to use the proxy settings instead.
* [Gateway errors](https://onecli.sh/docs/api-reference/gateway-errors.md) lists every answer the gateway can make.
* [How it works](https://onecli.sh/docs/how-it-works.md) follows a request from the agent to the API.


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