> For the complete documentation index, see [llms.txt](https://klaralabs.gitbook.io/klara-labs-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://klaralabs.gitbook.io/klara-labs-docs/klarity/integrations/together-ai.md).

# Together AI

### About Together AI

Together AI is a robust platform that provides cutting-edge tools for large language model inference and uncertainty analysis. It empowers teams to monitor, debug, and optimize their AI applications by delivering detailed insights and performance metrics.

### Use Klarity with Together AI

Integrate Klarity with Together AI to enhance your LLM applications with automated uncertainty and reasoning analysis. With this integration, you can:

* Evaluate your model’s confidence and identify blind spots.
* Debug and refine reasoning chains.
* Continuously optimize your AI workflows for improved reliability and performance.

```python
# basic_usage_together_ai.py
from klarity import UncertaintyEstimator
from klarity.core.analyzer import EntropyAnalyzer

# Initialize for Together AI model
estimator = UncertaintyEstimator(
    top_k=5,
    analyzer=EntropyAnalyzer(
        min_token_prob=0.01,
        insight_model="together:meta-llama/Llama-3.3-70B-Instruct-Turbo",
        insight_api_key="your_api_key",
    ),
    together_api_key="your_api_key",
    together_model="meta-llama/Llama-3.3-70B-Instruct-Turbo",
)

# Generate and analyze
prompt = "Your prompt"
generation_output = estimator._generate_with_together(prompt=prompt, max_new_tokens=10, temperature=0.7)

result = estimator.analyze_generation(generation_output)

# Print results
print(f"\nPrompt: {prompt}")
print(f"Generated text: {generation_output['text']}")

print("\nDetailed Token Analysis:")
for idx, metrics in enumerate(result.token_metrics):
    print(f"\nStep {idx}:")
    print(f"Raw entropy: {metrics.raw_entropy:.4f}")
    print(f"Semantic entropy: {metrics.semantic_entropy:.4f}")
    print("Top 3 predictions:")
    for i, pred in enumerate(metrics.token_predictions[:3], 1):
        print(f"  {i}. {pred.token} (prob: {pred.probability:.4f})")

if result.overall_insight:
    print("\nComprehensive Analysis:")
    print(result.overall_insight)
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://klaralabs.gitbook.io/klara-labs-docs/klarity/integrations/together-ai.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
