Skip to main content
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. 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), 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.
  • 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:
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:
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.

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:
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. A call with no credential gets this answer:
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.

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