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.
wgetand Python’surllibon OneCLI Cloud. Neither can talk to an HTTPS proxy.- Node’s
httpandhttpsmodules, 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. Nodefetchis 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 toagent.env. - An item in the vault for the host you call. The examples use the Test key for
httpbin.org.
Build the address
Puthttps://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:Make a call
httpbin.org/bearer answers 401 to a request with no token. A 200 shows that the gateway attached the Test key.
- curl
- Node fetch
If the proxy settings are on
Connecting an agent setsHTTPS_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:
Answers from the gateway
The gateway sets anX-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:
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 anx-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: Bearercan use the address form. - A client that sends its key as
x-api-keycannot. Connect it through the proxy settings instead.
Next steps
- Connect coding agents to use the proxy settings instead.
- Gateway errors lists every answer the gateway can make.
- How it works follows a request from the agent to the API.