# Send traffic

A program sends its requests through a device over the HTTP proxy or SOCKS5, with the strings the [quickstart](/guides/agents.md) wrote to `coronium-proxies.txt`. The edge, the one meter, counts every byte both ways. `POST /v1/fetch` and `POST /v1/routes/explain` answer only on the edge's own host and `local_only` anywhere else, because the buyer port takes no TLS; from anywhere else, check a route with `POST /app/api/proxy/test`, step 10 of the quickstart.

## Needs

`endpoint.state` `open` in `GET /app/api/proxy`: while it is `closed` no buyer traffic is carried, and the strings still hold `{host}` and `{port}`. Funds, once charging is on.

## Steps

1. As an HTTP proxy. A proxy string holds the credential, so it goes to curl in a config file, never as an argument.

```sh
umask 077
sed -n '1s/.*/proxy = "&"/p' coronium-proxies.txt > coronium-curl.conf
curl -sS -K coronium-curl.conf -o /dev/null -w '%{http_connect} %{http_code}\n' https://example.com/
```

Expect: `200 200`, the tunnel and then the target's status. The edge refuses with an error status such as `407` or `502`, a JSON body of `code`, `cause` and `fix`, and a `Coronium-Retry` header: `stop`, `wait-for-change` or `once-if-idempotent`. The route check names a route's code. Safe to repeat: as safe as the request itself.

2. Over SOCKS5. Make strings with `"protocol": "socks5"` in step 5 of the quickstart; `socks5h` lets the device look the name up.

```sh
umask 077
sed -n '1s/^socks5:/socks5h:/;1s/.*/proxy = "&"/p' coronium-proxies.txt > coronium-curl.conf
curl -sS -K coronium-curl.conf -o /dev/null -w '%{http_connect} %{http_code}\n' https://example.com/
```

Expect: `000 200`: SOCKS5 has no CONNECT status, so curl prints `000`, then the target's status. A SOCKS5 refusal is only a reply code, and curl ends with an error; the route check names the code. Safe to repeat: as safe as the request itself.

3. On the edge's own host only: `POST /v1/fetch` with `Authorization: Bearer <credential>` and `{"url": "..."}`, and an optional `selector`, a username, makes the request itself and answers `status`, `headers`, `body_base64`, `exit` and `bytes_billed`. `POST /v1/routes/explain` with `{"selector": "<username>"}` says where that username would go, and opens no stream.

## Refusals

| `code` | Do |
|---|---|
| `bad_credential` | use the account's credential; a replaced one stops working |
| `bad_options` | fix the username: [usernames](/guides/usernames.md) |
| `on_request` | no device fits now, and the demand is recorded: follow `Coronium-Retry` |
| `target_blocked` | the target is refused, such as mail ports or an IPv6 literal |
| `target_failed` | the target did not answer through the device |
| `unfunded`, `account_suspended`, `byte_cap_reached` | read `GET /app/api/billing` and tell your person |
| `traffic_stopped` | buyer traffic is stopped on this network: stop the job |
| `local_only` | a `/v1` call from another host: use the proxy, and the route check |
