---
title: 'Together.ai'
docname: 'togetherai'
---

## Overview

Together.ai hosts a number of language models and offers inference API with support for
chat completion, JSON completion, and tools call. You can use Instructor with Together.ai
as demonstrated below.

Please note that some Together.ai models support OutputMode::Tools or OutputMode::Json, which are much
more reliable than OutputMode::MdJson.

Mode compatibility:
- OutputMode::Tools - supported for selected models
- OutputMode::Json - supported for selected models
- OutputMode::MdJson - fallback mode


## Example

```php
<?php

use Cognesy\Polyglot\Inference\Inference;
use Cognesy\Utils\Str;

require 'examples/boot.php';

$answer = (new Inference)
    ->using('together') // see /config/llm.php
    ->with(
        messages: [['role' => 'user', 'content' => 'What is the capital of France']],
        options: ['max_tokens' => 64]
    )
    ->get();

echo "USER: What is capital of France\n";
echo "ASSISTANT: $answer\n";
assert(Str::contains($answer, 'Paris'));
?>
```