Metadata-Version: 2.4
Name: respan-instrumentation-cohere
Version: 0.1.0
Summary: Respan instrumentation plugin for Cohere
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: cohere (>=5.0.0,<6)
Requires-Dist: opentelemetry-instrumentation-cohere (>=0.60.0)
Requires-Dist: opentelemetry-semantic-conventions-ai (>=0.5.1,<0.6.0)
Requires-Dist: respan-sdk (>=2.6.1)
Requires-Dist: respan-tracing (>=2.17.0,<3.0.0)
Description-Content-Type: text/markdown

# respan-instrumentation-cohere

Respan instrumentation plugin for the Cohere Python SDK. It activates `opentelemetry-instrumentation-cohere` and normalizes Cohere spans to the Respan span contract before export.

## Install

```bash
pip install respan-ai respan-instrumentation-cohere cohere python-dotenv
```

## Environment

| Variable | Required | Description |
|----------|----------|-------------|
| `RESPAN_API_KEY` | Yes | Respan API key used to export traces. |
| `RESPAN_BASE_URL` | No | Respan API base URL. Defaults to `https://api.respan.ai/api`. |
| `CO_API_KEY` | Yes | Cohere API key used by the Cohere SDK. |

## Quickstart

```python
import os

import cohere
from dotenv import load_dotenv
from respan import Respan, workflow
from respan_instrumentation_cohere import CohereInstrumentor

load_dotenv()

respan = Respan(
    api_key=os.environ["RESPAN_API_KEY"],
    instrumentations=[CohereInstrumentor()],
)
client = cohere.ClientV2(api_key=os.environ["CO_API_KEY"])


@workflow(name="cohere_chat_quickstart")
def run_chat() -> str:
    response = client.chat(
        model=os.getenv("COHERE_CHAT_MODEL", "command-a-03-2025"),
        messages=[
            {
                "role": "user",
                "content": "Say hello in three languages.",
            }
        ],
    )
    return response.message.content[0].text


print(run_chat())
respan.flush()
```

## Notes

The upstream Cohere OpenTelemetry instrumentor emits Cohere SDK spans. This package adds a Respan span processor that:

- sets `gen_ai.system` to `cohere`
- adds `respan.entity.log_type`
- publishes both modern and legacy token usage attributes
- converts indexed tool definitions and tool calls into JSON string attributes
- strips off-contract shortcut aliases before export

