> ## Documentation Index
> Fetch the complete documentation index at: https://docs.together.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Composio

> Use Composio with Together AI.

Composio allows developers to integrate external tools and services into their AI applications. It handles tool calling, webhooks, authentication, and more.

You need to register on a Composio account. Sign up here if you haven't already to get their API key [https://platform.composio.dev/](https://platform.composio.dev/).

## Install libraries

```shell Python theme={null}
uv add together composio-togetherai
```

```shell TypeScript theme={null}
npm install @composio/core @composio/vercel @ai-sdk/togetherai ai
```

Set your `TOGETHER_API_KEY` and `COMPOSIO_API_KEY` environment variables.

```bash Shell theme={null}
export TOGETHER_API_KEY=***
export COMPOSIO_API_KEY=***
```

## Example

In this example, you will use Together AI to star a repository on GitHub using Composio Tools.

```python Python theme={null}
from composio_togetherai import ComposioToolSet, App
from together import Together

client = Together()
toolset = ComposioToolSet()
```

```typescript TypeScript theme={null}
/*
We use the Vercel AI SDK with the Together provider to 
enable type checking to work correctly for tools and 
to simplify the Composio integration. 
This flow enables us to directly execute tool calls
without having to use composio.provider.handleToolCalls.
*/

import { Composio } from "@composio/core";
import { VercelProvider } from "@composio/vercel";
import { createTogetherAI } from "@ai-sdk/togetherai";
import { generateText } from "ai";

export const together = createTogetherAI({
  apiKey: process.env.TOGETHER_API_KEY ?? "",
});

const composio = new Composio({
  apiKey: process.env.COMPOSIO_API_KEY ?? "",
  provider: new VercelProvider(),
});
```

### Connect your GitHub account

You need to have an active GitHub Integration in Composio. See the [Composio GitHub setup video](https://www.youtube.com/watch?v=LmyWy4LiedQ).

```python Python theme={null}
request = toolset.initiate_connection(app=App.GITHUB)
print(f"Open this URL to authenticate: {request.redirectUrl}")
```

```bash Shell theme={null}
composio login
composio add github
```

### Get all GitHub tools

You can get all the tools for a given app as shown below, but you can get specific actions and filter actions using usecase & tags.

```python Python theme={null}
tools = toolset.get_tools(apps=[App.GITHUB])
```

```typescript TypeScript theme={null}
const userId = "default"; // replace with user id from composio
const tools = await composio.tools.get(userId, {
  toolkits: ['github'],
});
```

### Create a chat completion with tools

```python Python theme={null}
response = client.chat.completions.create(
    tools=tools,
    model="meta-models/Muse-Glimmer-30B",
    messages=[
        {
            "role": "user",
            "content": "Star the repo 'togethercomputer/together-cookbook'",
        }
    ],
)

res = toolset.handle_tool_calls(response)
print(res)
```

```typescript TypeScript theme={null}
const responseGithub = await generateText({
    model: together("meta-models/Muse-Glimmer-30B"),
    messages: [
      {
        role: "user",
        content: "Star the repo 'togethercomputer/together-cookbook'",
      },
    ],
    tools,
    toolChoice: "required",
});

console.log(responseGithub);
```

## Next steps

> [!NOTE]
>
> ### Composio - Together AI Cookbook
>
> Explore the in-depth [Composio Cookbook](https://github.com/togethercomputer/together-cookbook/blob/main/agents/Composio/Agents_Composio.ipynb) to learn how to automate emails with LLMs.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.