Metadata-Version: 2.4
Name: respan-instrumentation-portkey
Version: 0.1.0
Summary: Respan instrumentation plugin for Portkey
License: Apache 2.0
Author: Respan
Author-email: team@respan.ai
Requires-Python: >=3.11,<3.14
Classifier: License :: Other/Proprietary License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Requires-Dist: openinference-instrumentation-portkey (>=0.1.11)
Requires-Dist: opentelemetry-semantic-conventions-ai (>=0.4.1)
Requires-Dist: portkey-ai (>=2.3.1)
Requires-Dist: respan-instrumentation-openinference (>=1.2.2)
Requires-Dist: respan-sdk (>=2.5.0)
Requires-Dist: respan-tracing (>=2.16.1,<3.0.0)
Description-Content-Type: text/markdown

# respan-instrumentation-portkey

Respan instrumentation plugin for Portkey. Wraps OpenInference's Portkey instrumentor, translates spans into the Respan tracing shape, and strips off-contract helper aliases before export.

## Configuration

### 1. Install

```bash
pip install respan-instrumentation-portkey
```

### 2. Set Environment Variables

| Variable | Required | Description |
|----------|----------|-------------|
| `RESPAN_API_KEY` | Yes | Your Respan API key for trace export. |
| `RESPAN_BASE_URL` | No | Defaults to `https://api.respan.ai/api`. |
| `PORTKEY_API_KEY` | Yes | Your Portkey API key for Portkey Gateway calls. |
| `PORTKEY_PROVIDER` or `PORTKEY_CONFIG` | Yes | Portkey provider slug or config slug. |

## Quickstart

```python
import os
from dotenv import load_dotenv

load_dotenv()

from portkey_ai import Portkey
from respan import Respan, workflow
from respan_instrumentation_portkey import PortkeyInstrumentor

respan = Respan(
    api_key=os.environ["RESPAN_API_KEY"],
    base_url=os.getenv("RESPAN_BASE_URL", "https://api.respan.ai/api"),
    instrumentations=[PortkeyInstrumentor()],
)

client = Portkey(
    api_key=os.environ["PORTKEY_API_KEY"],
    provider=os.getenv("PORTKEY_PROVIDER"),
    config=os.getenv("PORTKEY_CONFIG"),
)


@workflow(name="portkey_chat_completion")
def run_chat() -> str:
    response = client.chat.completions.create(
        model=os.getenv("PORTKEY_MODEL", "gpt-4o-mini"),
        messages=[{"role": "user", "content": "Say hello from Portkey."}],
    )
    return response.choices[0].message.content or ""


try:
    print(run_chat())
finally:
    respan.flush()
    respan.shutdown()
```

## Further Reading

See the [Respan example projects](https://github.com/respanai/respan-example-projects) for runnable scripts.

