Youtube

Learn how to use Youtube with Composio

Overview

SLUG: YOUTUBE

Description

YouTube is a video-sharing platform with user-generated content, live streaming, and monetization opportunities, widely used for marketing, education, and entertainment

Authentication Details

client_id
stringRequired
client_secret
stringRequired
full
stringDefaults to https://www.googleapis.com/youtube/v3Required
oauth_redirect_uri
stringDefaults to https://backend.composio.dev/api/v1/auth-apps/add
scopes
stringDefaults to https://www.googleapis.com/auth/youtube https://www.googleapis.com/auth/youtube.channel-memberships.creator https://www.googleapis.com/auth/youtube.force-ssl https://www.googleapis.com/auth/youtube.readonly https://www.googleapis.com/auth/youtube.upload https://www.googleapis.com/auth/youtubepartner https://www.googleapis.com/auth/youtubepartner-channel-audit
bearer_token
string

Connecting to Youtube

Create an auth config

Use the dashboard to create an auth config for the Youtube toolkit. This allows you to connect multiple Youtube accounts to Composio for agents to use.

1

Select App

Navigate to Youtube.

2

Configure Auth Config Settings

Select among the supported auth schemes of and configure them here.

3

Create and Get auth config ID

Click “Create Youtube Auth Config”. After creation, copy the displayed ID starting with ac_. This is your auth config ID. This is not a sensitive ID — you can save it in environment variables or a database. This ID will be used to create connections to the toolkit for a given user.

Connect Your Account

Using OAuth2

1from composio import Composio
2
3# Replace these with your actual values
4youtube_auth_config_id = "ac_YOUR_YOUTUBE_CONFIG_ID" # Auth config ID created above
5user_id = "0000-0000-0000" # UUID from database/application
6
7composio = Composio()
8
9
10def authenticate_toolkit(user_id: str, auth_config_id: str):
11 connection_request = composio.connected_accounts.initiate(
12 user_id=user_id,
13 auth_config_id=auth_config_id,
14 )
15
16 print(
17 f"Visit this URL to authenticate Youtube: {connection_request.redirect_url}"
18 )
19
20 # This will wait for the auth flow to be completed
21 connection_request.wait_for_connection(timeout=15)
22 return connection_request.id
23
24
25connection_id = authenticate_toolkit(user_id, youtube_auth_config_id)
26
27# You can also verify the connection status using:
28connected_account = composio.connected_accounts.get(connection_id)
29print(f"Connected account: {connected_account}")

Tools

Executing tools

To prototype you can execute some tools to see the responses and working on the Youtube toolkit’s playground

Python
1from composio import Composio
2from openai import OpenAI
3import json
4
5openai = OpenAI()
6composio = Composio()
7
8# User ID must be a valid UUID format
9user_id = "0000-0000-0000" # Replace with actual user UUID from your database
10
11tools = composio.tools.get(user_id=user_id, toolkits=["YOUTUBE"])
12
13print("[!] Tools:")
14print(json.dumps(tools))
15
16def invoke_llm(task = "What can you do?"):
17 completion = openai.chat.completions.create(
18 model="gpt-4o",
19 messages=[
20 {
21 "role": "user",
22 "content": task, # Your task here!
23 },
24 ],
25 tools=tools,
26 )
27
28 # Handle Result from tool call
29 result = composio.provider.handle_tool_calls(user_id=user_id, response=completion)
30 print(f"[!] Completion: {completion}")
31 print(f"[!] Tool call result: {result}")
32
33invoke_llm()

Tool List

Tool Name: List captions

Description

Retrieves a list of caption tracks for a youtube video, returning an empty list if no captions exist or failing if the video id is invalid or not found.

Action Parameters

part
stringDefaults to snippet
videoId
stringRequired

Action Response

data
objectRequired
error
string
successful
booleanRequired

Tool Name: Update thumbnail

Description

Sets the custom thumbnail for a youtube video using an image from thumbnailurl; the authenticated user must have permission to edit the video.

Action Parameters

thumbnailUrl
stringRequired
videoId
stringRequired

Action Response

data
objectRequired
error
string
successful
booleanRequired

Tool Name: Get channel ID by handle

Description

Retrieves the youtube channel id for a specific youtube channel handle.

Action Parameters

channel_handle
stringRequired

Action Response

data
objectRequired
error
string
successful
booleanRequired

Tool Name: List channel videos

Description

Lists videos from a specified youtube channel, ensuring results are of `type: 'video'`.

Action Parameters

channelId
stringRequired
maxResults
integerDefaults to 5
pageToken
string
part
stringDefaults to snippet

Action Response

data
objectRequired
error
string
successful
booleanRequired

Tool Name: List user playlists

Description

Retrieves playlists owned by the authenticated user, implicitly using mine=true.

Action Parameters

maxResults
integerDefaults to 5
pageToken
string
part
stringDefaults to snippet

Action Response

data
objectRequired
error
string
successful
booleanRequired

Tool Name: List user subscriptions

Description

Retrieves the authenticated user's youtube channel subscriptions, allowing specification of response parts and pagination.

Action Parameters

maxResults
integerDefaults to 5
pageToken
string
part
stringDefaults to snippet,contentDetails

Action Response

data
objectRequired
error
string
successful
booleanRequired

Tool Name: Download YouTube caption track

Description

Downloads a specific youtube caption track, which must be owned by the authenticated user, and returns its content as text.

Action Parameters

id
stringRequired
tfmt
stringDefaults to srt

Action Response

data
objectRequired
error
string
successful
booleanRequired

Tool Name: Search YouTube

Description

Searches youtube for videos, channels, or playlists using a query term, returning the raw api response.

Action Parameters

maxResults
integerDefaults to 5
pageToken
string
part
stringDefaults to snippet
q
stringRequired
type
stringDefaults to video

Action Response

data
objectRequired
error
string
successful
booleanRequired

Tool Name: Subscribe to channel

Description

Subscribes the authenticated user to a specified youtube channel, identified by its unique `channelid` which must be valid and existing.

Action Parameters

channelId
stringRequired

Action Response

data
objectRequired
error
string
successful
booleanRequired

Tool Name: Update video

Description

Updates metadata for a youtube video identified by videoid, which must exist; an empty list for tags removes all existing tags.

Action Parameters

categoryId
string
description
string
privacyStatus
string
tags
array
title
string
videoId
stringRequired

Action Response

data
objectRequired
error
string
successful
booleanRequired

Tool Name: Upload video

Description

Uploads a video from a local file path to a youtube channel; the video file must be in a youtube-supported format.

Action Parameters

categoryId
stringRequired
description
stringRequired
privacyStatus
stringRequired
tags
arrayRequired
title
stringRequired
videoFilePath
stringRequired

Action Response

data
objectRequired
error
string
successful
booleanRequired

Tool Name: Video details

Description

Retrieves specified information parts (e.g., snippet, contentdetails, statistics) for a youtube video, identified by its id.

Action Parameters

id
stringRequired
part
stringDefaults to snippet,contentDetails,statistics

Action Response

data
objectRequired
error
string
successful
booleanRequired