Initialize the Netra SDK with Together AI instrumentation enabled. The SDK automatically traces all Together AI API calls once initialized.
from netra import Netrafrom together import Togetherimport os# Initialize Netra with Together AI instrumentationNetra.init( app_name="my-ai-app", headers=f"x-api-key={os.environ.get('NETRA_API_KEY')}", trace_content=True)# Use Together AI client as usual - all calls are automatically tracedclient = Together(api_key=os.environ.get("TOGETHER_API_KEY"))response = client.chat.completions.create( model="mistralai/Mixtral-8x7B-Instruct-v0.1", messages=[ {"role": "user", "content": "What is observability?"} ])print(response.choices[0].message.content)
import { Netra } from "netra-sdk";import Together from "together-ai";async function main() { // Initialize Netra with Together AI instrumentation (must await) await Netra.init({ appName: "my-ai-app", headers: `x-api-key=${process.env.NETRA_API_KEY}`, traceContent: true }); // Use Together AI client as usual - all calls are automatically traced const together = new Together({ apiKey: process.env.TOGETHER_API_KEY }); const response = await together.chat.completions.create({ model: "mistralai/Mixtral-8x7B-Instruct-v0.1", messages: [ { role: "user", content: "What is observability?" } ] }); console.log(response.choices[0].message.content);}main();
The SDK automatically handles streaming responses and captures the complete output:
stream = client.chat.completions.create( model="mistralai/Mixtral-8x7B-Instruct-v0.1", messages=[{"role": "user", "content": "Tell me a story"}], stream=True)for chunk in stream: if chunk.choices[0].delta.content: print(chunk.choices[0].delta.content, end="")
const stream = await together.chat.completions.create({ model: "mistralai/Mixtral-8x7B-Instruct-v0.1", messages: [{ role: "user", content: "Tell me a story" }], stream: true});for await (const chunk of stream) { process.stdout.write(chunk.choices[0]?.delta?.content || "");}
Embedding operations are also automatically instrumented:
embeddings = client.embeddings.create( model="togethercomputer/m2-bert-80M-8k-retrieval", input="The quick brown fox jumps over the lazy dog")print(embeddings.data[0].embedding)
const embeddings = await together.embeddings.create({ model: "togethercomputer/m2-bert-80M-8k-retrieval", input: "The quick brown fox jumps over the lazy dog"});console.log(embeddings.data[0].embedding);
Control which integrations are enabled using the instruments or blockInstruments configuration:
from netra import Netrafrom netra.instrumentation.instruments import InstrumentSet# Only enable Together AI instrumentationNetra.init( headers=f"x-api-key={os.environ.get('NETRA_API_KEY')}", instruments={InstrumentSet.TOGETHER})# Or block specific instrumentationsNetra.init( headers=f"x-api-key={os.environ.get('NETRA_API_KEY')}", block_instruments={InstrumentSet.HTTPX})
import { Netra, NetraInstruments } from "netra-sdk";// Only enable Together AI instrumentationawait Netra.init({ headers: `x-api-key=${process.env.NETRA_API_KEY}`, instruments: new Set([NetraInstruments.TOGETHER])});// Or block specific instrumentationsawait Netra.init({ headers: `x-api-key=${process.env.NETRA_API_KEY}`, blockInstruments: new Set([NetraInstruments.HTTP])});