Skip to navigation

Observability for Straitly with Opik

View as Markdown

Straitly 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.

Account Setup

Comet provides a hosted version of the Opik platform. Simply create an account and grab your API Key.

You can also run the Opik platform locally, see the installation guide for more information.

Getting Started

Installation

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

pip install opik openai

Configuring Opik

Configure the Opik Python SDK for your deployment type. See the Python SDK Configuration guide 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 (see the Straitly quickstart).

Set your API key as an environment variable:

export STRAITLY_API_KEY="YOUR_STRAITLY_API_KEY"

Or set it programmatically:

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 to automatically log Straitly calls as generations in Opik.

Simple LLM Call

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:

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.