Notebooks
L
Langfuse
Integration Togetherai

Integration Togetherai

observabilityllmsgenaicookbookprompt-managementhacktoberfestlarge-language-modelsnextraLangfuselangfuse-docs

Observability for Together.ai with Langfuse

This guide shows you how to integrate Together.ai with Langfuse. Together's API endpoints for chat, language and code, images, and embeddings are fully compatible with OpenAI's API. This allows us to use the Langfuse OpenAI drop-in replacement to trace all parts of your application.

What is Together.ai? Together.ai empowers developers and researchers to train, fine-tune, and deploy generative AI models, offering access to over 100 open-source models on both serverless and dedicated instances. The platform emphasizes decentralized cloud services, enabling organizations of all sizes to customize AI solutions using their own data.

What is Langfuse? Langfuse is an open source LLM engineering platform that helps teams trace API calls, monitor performance, and debug issues in their AI applications.

Step 1: Install Dependencies

Make sure you have installed the necessary Python packages:

[ ]

Step 2: Set Up Environment Variables

[2]

Step 3: Langfuse OpenAI drop-in Replacement

In this step we use the native OpenAI drop-in replacement by importing from langfuse.openai import openai.

To start using Together with OpenAI's client libraries, pass in your Together API key to the api_key option, and change the base_url to https://api.together.xyz/v1:

[3]

Note: The OpenAI drop-in replacement is fully compatible with the Low-Level Langfuse Python SDKs and @observe() decorator to trace all parts of your application.

Step 4: Run An Example

The following cell demonstrates how to call Together.ai's chat model using the traced OpenAI client. All API calls will be automatically traced by Langfuse.

[ ]

Step 5: See Traces in Langfuse

After running the example model call, you can see the traces in Langfuse. You will see detailed information about your Together.ai API calls, including:

  • Request parameters (model, messages, temperature, etc.)
  • Response content
  • Token usage statistics
  • Latency metrics

Langfuse Trace Example

Public example trace link in Langfuse