openinference

OpenInference Together AI Instrumentation

pypi

Python auto-instrumentation library for the Together AI Python client.

Chat completion calls made with the together client (Together and AsyncTogether) are traced and exported as OpenInference LLM spans, capturing the input messages, output messages, invocation parameters, tool calls, streaming output, and token counts.

These traces are fully OpenTelemetry compatible and can be sent to an OpenTelemetry collector for viewing, such as Arize Phoenix or Arize AX.

Supported Features

Requires together >= 2.0.0.

Installation

pip install openinference-instrumentation-together

PyPI package: openinference-instrumentation-together

Quickstart

pip install openinference-instrumentation-together together arize-phoenix opentelemetry-sdk opentelemetry-exporter-otlp

Start Phoenix as a collector (default http://localhost:6006), then:

from openinference.instrumentation.together import TogetherInstrumentor
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import SimpleSpanProcessor

endpoint = "http://127.0.0.1:6006/v1/traces"
tracer_provider = TracerProvider()
tracer_provider.add_span_processor(SimpleSpanProcessor(OTLPSpanExporter(endpoint)))

TogetherInstrumentor().instrument(tracer_provider=tracer_provider)

Run a chat completion. Set the TOGETHER_API_KEY environment variable with your key.

from together import Together

client = Together()
response = client.chat.completions.create(
    model="meta-llama/Llama-3.3-70B-Instruct-Turbo",
    messages=[{"role": "user", "content": "Why is the sky blue?"}],
)
print(response.choices[0].message.content)

Streaming works the same way — the span is finished when the stream is exhausted:

stream = client.chat.completions.create(
    model="meta-llama/Llama-3.3-70B-Instruct-Turbo",
    messages=[{"role": "user", "content": "Write a haiku about observability."}],
    stream=True,
)
for chunk in stream:
    if chunk.choices and chunk.choices[0].delta.content:
        print(chunk.choices[0].delta.content, end="", flush=True)

Runnable examples — including async usage, streaming with a reasoning model, and tool calls — are in the examples/ directory.

More Info