Observability for Together AI with Opik
Together AI provides fast inference for leading open-source models including Llama, Mistral, Qwen, and many others.
Wrap your Together client with track_together and every chat completion is logged to Opik with its messages, response, model and token usage. Streaming and the async client work out of the box.
Together’s SDK is OpenAI-shaped but defines its own client and stream classes, so track_openai cannot patch it — use track_together instead.
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
Configuring Opik
Run opik configure and follow the prompts. See the Python SDK Configuration guide for other options, such as configuring Opik in code or with environment variables.
Configuring Together AI
Set your Together AI API key as an environment variable:
Logging LLM calls
Create a Together client, wrap it with track_together, and use it as usual:
Advanced Usage
Using with the @track decorator
Calls made with a tracked client inside a function decorated with @track are nested under that function’s trace:
Streaming
Pass stream=True and iterate as usual. The span is ended once the stream is fully consumed, and the chunks are aggregated into a single logged response:
Async client
track_together works with together.AsyncTogether as well, including streaming:
Cost Tracking
Opik records the token usage Together returns on each call. Cost is not estimated for Together spans yet, so they show token counts without a price.
Supported Methods
track_together logs chat.completions.create() on both together.Together and together.AsyncTogether, with and without streaming. Other methods aren’t logged; to trace them, call them inside a function decorated with @track.
Using Together AI through LiteLLM
If you call Together AI through LiteLLM rather than the Together SDK, use the LiteLLM integration instead of track_together.
Configuring Opik and LiteLLM
Configuring Opik
To start tracking your Together AI calls, you’ll need to have both opik and litellm installed. You can install them using pip:
In addition, you can configure Opik using the opik configure command which will prompt you for the correct local server address or if you are using the Cloud platform your API key:
Configuring Together AI
You’ll need to set your Together AI API key as an environment variable:
Logging LLM calls through LiteLLM
In order to log the LLM calls to Opik, you will need to create the OpikLogger callback. Once the OpikLogger callback is created and added to LiteLLM, you can make calls to LiteLLM as you normally would:
Logging LiteLLM calls within a tracked function
If you are using LiteLLM within a function tracked with the @track decorator, you will need to pass the current_span_data as metadata to the litellm.completion call: