Integrations

Opik

Trace Drex decision requests in Opik by wrapping the TypeSafe client, with the model and token usage on each span.

Opik traces LLM calls. Its TypeSafe integration, track_typesafe, wraps the typesafe-sdk client, and Drex answers that client's requests, so wrapping a client that points at Drex traces Drex calls. See Questions and Reading answers.

Verified with opik 2.2.137 and typesafe-sdk 0.7.5 against https://console.nace.ai: the wrapped call succeeds, and the span Opik builds names the model drex-max and carries the token usage Drex reported. The span was read from the client's outgoing message queue. Nothing was sent to an Opik backend, Comet's cloud or a self-hosted server, so what the Opik UI shows is not verified.

Setup

pip install opik typesafe-sdk
export TYPESAFE_API_KEY=nace_sk_...

Create the key as shown in Authentication. Set TYPESAFE_BASE_URL to https://console.nace.ai (the host, without /v1); the sample reads it. For Drex on your own infrastructure, use that deployment's URL. Configure Opik itself as its documentation describes.

Trace a request

Set the model on every call. The SDK's default model, jev-latest, is refused by Drex with a 422 (unknown model).

import os
from typesafe_sdk import Noul, TypeSafeClient
from opik.integrations.typesafe import track_typesafe

client = track_typesafe(
    TypeSafeClient(
        api_key=os.environ["TYPESAFE_API_KEY"],
        base_url=os.environ["TYPESAFE_BASE_URL"],
        timeout=60,
    ),
    project_name="drex-evals",
)

result = client.system_one(
    "I was charged twice and want a refund.",
    {"refund": Noul(instructions="Is the customer asking for a refund?")},
    model="drex-max",
)
result.answers["refund"].noul   # probability of yes

timeout=60 is in seconds: the SDK's default of 10 seconds is shorter than Drex can take on a large request. See Migrate from TypeSafe. The async client, AsyncTypeSafeClient, works the same way against Drex; it was not checked with track_typesafe.

What works and what doesn't

  • noul and choice questions, and the models drex-max, drex-v2.0 and drex-max-v1.1, worked through the SDK. List the model ids you can send with GET /v1/models; see Models.
  • box questions aren't supported by Drex, which answers 422 and says so.
  • A score question has not been tried through Opik. Drex used to return its legend as a list of level labels, which typesafe-sdk 0.7.5 rejects when used directly (it validates an object keyed by level), and Opik wraps that client. Drex now sends the TypeSafe SDK an object keyed by level, recognized by its X-TypeSafe-SDK header, and X-Nace-Legend: array or object overrides it; see Reading answers. That is available once the change is deployed. An object legend validates against the real typesafe-sdk ScoreAnswer model offline, but a live score call through Opik against a deployment has not been run yet. Until you have tested one, ask score questions with the Python or TypeScript Nace SDK, or over HTTP.

Drex enforces its own request limits; see Limits. A failed request raises the SDK's error, never a low score; see Errors and retries.

On this page