Metadata-Version: 2.5
Name: uplinkswitch-hook
Version: 0.1.0
Summary: Zero-code runtime interceptor for OpenAI and Anthropic SDK calls
Project-URL: Homepage, https://uplinkswitch.ai
Project-URL: Repository, https://gitlab.com/uplinkswitch/uplinkswitch-hook
Author: Uplink Switch LLC
License-Expression: MIT
Requires-Python: >=3.9
Provides-Extra: test
Requires-Dist: anthropic; extra == 'test'
Requires-Dist: httpx; extra == 'test'
Requires-Dist: openai; extra == 'test'
Requires-Dist: pytest; extra == 'test'
Requires-Dist: requests; extra == 'test'
Description-Content-Type: text/markdown

# UplinkSwitch runtime hooks

Route existing OpenAI and Anthropic SDK calls through UplinkSwitch without editing application code. The hooks intercept `api.openai.com` and `api.anthropic.com`, preserve methods, bodies and other headers, and replace the authentication headers with your destination key. Both packages have no runtime dependencies.

## Node.js 18+

```sh
npm i -D @uplinkswitch/hook
export UPLINKSWITCH_API_KEY="your-key"
export NODE_OPTIONS="-r @uplinkswitch/hook/register"
node app.js
```

The hook must be installed in the runtime environment, including when production installs omit development dependencies. It covers global fetch and Node's http/https request/get APIs. Independently imported HTTP implementations are outside its scope.

## Python 3.9+

```sh
pip install uplinkswitch-hook
export UPLINKSWITCH_API_KEY="your-key"
python app.py
```

The installed wheel includes a startup `.pth` file. Normal interpreter startup activates routing for httpx, httpx2 and requests, including the standard OpenAI and Anthropic clients. Install the wheel in the same environment that runs your application. Python's `-S` option disables site initialization and automatic activation. Existing httpx clients created before manual `install()` are not changed.

## Configuration

| Variable | Meaning |
| --- | --- |
| `UPLINKSWITCH_API_KEY` | Required destination key. Unset means no interception. |
| `UPLINKSWITCH_BASE_URL` | Destination base URL; defaults to `https://api.uplinkswitch.com/v1`. Trailing slashes are removed. |
| `UPLINKSWITCH_INTERCEPT_HOSTS` | Comma-separated additional hostnames to intercept. |

If the destination base path ends in `/v1`, the original leading `/v1` is removed before joining paths. Existing authorization and x-api-key headers are replaced; when neither exists, both are added. Unrelated requests continue unchanged. Set environment variables before startup; installation is idempotent. Each active process prints one destination-host activation line to stderr. Node also prints one line when its key is unset.

## Docker

```dockerfile
ENV NODE_OPTIONS="-r @uplinkswitch/hook/register" UPLINKSWITCH_API_KEY=""
# Supply UPLINKSWITCH_API_KEY at runtime using your secret manager.
CMD ["node", "app.js"]
```

## Sister brands

Use the chosen brand's API key and either base URL:

```sh
export UPLINKSWITCH_BASE_URL="https://api.pentestllm.ai/v1"
export UPLINKSWITCH_API_KEY="your-pentestllm-key"
# Or:
export UPLINKSWITCH_BASE_URL="https://api.uncensoredllm.ai/v1"
export UPLINKSWITCH_API_KEY="your-uncensoredllm-key"
```

The hooks collect no telemetry: no request content or keys are logged, and intercepted requests are sent only to the configured base URL. The single activation line contains the destination host. Unrelated traffic retains its original destination; HTTP clients retain their normal redirect behavior.

## Development

Run `npm ci && node --test` in `packages/node-hook`. In `packages/python-hook`, create a venv with `python3 -m venv .venv`, install `.[test]`, `build`, and `twine`, build with `python -m build`, install the resulting wheel, and run `python -I -m pytest`. Tests use only a local HTTP server and fake keys.

MIT — Uplink Switch LLC.
