> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://www.comet.com/docs/opik/llms.txt.

# Observability for Straitly with Opik

> Learn how to integrate Straitly with Opik using the OpenAI SDK wrapper to trace and evaluate LLM calls across 150+ models.

[Straitly](https://straitly.ai/) is an AI gateway that provides one OpenAI-compatible API key and base URL for 150+ models, including Claude, GPT, Gemini, Grok, and DeepSeek.

## Gateway Overview

Straitly provides a single OpenAI-compatible endpoint for multi-model applications:

* **Unified API**: Access 150+ models through `https://api.straitly.ai/v1` with the OpenAI SDK (Chat Completions and Responses) or the Anthropic Messages SDK.
* **Drop-in migration**: Switch existing OpenAI SDK code by updating the base URL and API key.
* **Automatic failover**: Requests move to another provider serving the same model if one goes down.
* **Prepaid per-token billing**: Pay per token from prepaid credits with no subscription, no minimum, and no charge for failed requests.

For the full list of supported model IDs, see the [Straitly models catalog](https://straitly.ai/models).

## Account Setup

[Comet](https://www.comet.com/site?from=llm\&utm_source=opik\&utm_medium=colab\&utm_content=straitly\&utm_campaign=opik) provides a hosted version of the Opik platform. [Simply create an account](https://www.comet.com/signup?from=llm\&utm_source=opik\&utm_medium=colab\&utm_content=straitly\&utm_campaign=opik) and grab your API Key.

> You can also run the Opik platform locally, see the [installation guide](https://www.comet.com/docs/opik/self-host/overview/?from=llm\&utm_source=opik\&utm_medium=colab\&utm_content=straitly\&utm_campaign=opik) for more information.

## Getting Started

### Installation

First, ensure you have both `opik` and `openai` packages installed:

```bash wordWrap
pip install opik openai
```

### Configuring Opik

Configure the Opik Python SDK for your deployment type. See the [Python SDK Configuration guide](/docs/opik/tracing/advanced/sdk_configuration) for detailed instructions on:

* **CLI configuration**: `opik configure`
* **Code configuration**: `opik.configure()`
* **Self-hosted vs Cloud vs Enterprise** setup
* **Configuration files** and environment variables

### Configuring Straitly

You'll need a Straitly API key, which you can create in [Straitly](https://straitly.ai/) (see the [Straitly quickstart](https://straitly.ai/docs/quickstart)).

Set your API key as an environment variable:

```bash wordWrap
export STRAITLY_API_KEY="YOUR_STRAITLY_API_KEY"
```

Or set it programmatically:

```python wordWrap
import os
import getpass

if "STRAITLY_API_KEY" not in os.environ:
    os.environ["STRAITLY_API_KEY"] = getpass.getpass("Enter your Straitly API key: ")
```

## Logging LLM Calls

Since Straitly provides an OpenAI-compatible API, you can use the [Opik OpenAI SDK wrapper](/docs/opik/integrations/openai) to automatically log Straitly calls as generations in Opik.

### Simple LLM Call

```python wordWrap
import os
from opik.integrations.openai import track_openai
from openai import OpenAI

# Create an OpenAI client pointed at Straitly's base URL
client = OpenAI(
    api_key=os.environ["STRAITLY_API_KEY"],
    base_url="https://api.straitly.ai/v1",
)

# Wrap the client with Opik tracking
client = track_openai(client, project_name="straitly-integration-demo")

# Make a chat completion request
response = client.chat.completions.create(
    model="deepseek/deepseek-v4-1-flash-1017",
    messages=[
        {"role": "system", "content": "You are a helpful AI assistant."},
        {"role": "user", "content": "What is the largest city in France?"},
    ],
)

print(response.choices[0].message.content)
```

## Advanced Usage

### Using with the `@track` decorator

If you have multiple steps in your LLM pipeline, you can use the `@track` decorator to group nested Straitly calls into a single trace:

```python wordWrap
import os
from opik import track
from opik.integrations.openai import track_openai
from openai import OpenAI

client = OpenAI(
    api_key=os.environ["STRAITLY_API_KEY"],
    base_url="https://api.straitly.ai/v1",
)
client = track_openai(client)


@track
def generate_response(prompt: str):
    response = client.chat.completions.create(
        model="deepseek/deepseek-v4-1-flash-1017",
        messages=[
            {"role": "system", "content": "You are a helpful AI assistant."},
            {"role": "user", "content": prompt},
        ],
    )
    return response.choices[0].message.content


@track
def refine_response(initial_response: str):
    response = client.chat.completions.create(
        model="claude-sonnet-5-5",
        messages=[
            {"role": "system", "content": "Summarize text clearly in one sentence."},
            {"role": "user", "content": f"Summarize this: {initial_response}"},
        ],
    )
    return response.choices[0].message.content


@track(project_name="straitly-integration-demo")
def generate_and_refine(prompt: str):
    initial = generate_response(prompt)
    return refine_response(initial)


result = generate_and_refine("Explain quantum computing in two sentences.")
print(result)
```

The trace will show both model calls as nested LLM spans under the `generate_and_refine` trace.

## Further Improvements

If you have suggestions for improving the Straitly integration, please let us know by opening an issue on [GitHub](https://github.com/comet-ml/opik/issues).