# pi-openrouter-session

[![npm version](https://img.shields.io/npm/v/@eissar/pi-openrouter-session)](https://www.npmjs.com/package/@eissar/pi-openrouter-session)
[![License: Unlicense](https://img.shields.io/badge/license-Unlicense-blue)](LICENSE)

Injects the current Pi session ID as `session_id` into every OpenRouter provider request.

OpenRouter can use this to correlate sessions across requests for analytics, debugging, or per-session rate limiting.

## Install

```bash
pi install npm:@eissar/pi-openrouter-session
```

Then `/reload` in Pi (or restart).

## How It Works

This Pi extension listens for the `before_provider_request` event and patches the outgoing request payload with the current Pi session ID (`session_id`). The session ID is obtained from `ctx.sessionManager.getSessionId()`.

OpenRouter receives the `session_id` field and can use it to group related requests — useful for tracking conversation flows, debugging API usage, or applying per-session rate limits.
you can read about how openrouter handles that here: <https://openrouter.ai/docs/guides/features/broadcast/overview#optional-trace-data>

## Source

- **npm:** [@eissar/pi-openrouter-session](https://www.npmjs.com/package/@eissar/pi-openrouter-session)
- **GitHub:** [eissar/pi-openrouter-session](https://github.com/eissar/pi-openrouter-session)

Install from GitHub directly:

```bash
pi install git:github.com/eissar/pi-openrouter-session
```

## License

[Unlicense](LICENSE) — public domain.
