All YouTube search requests go through this single endpoint. AIsa handles authentication with the underlying YouTube data source — you only need your AIsa API key.
# Use the sp token from a previous response to get the next pagecurl -s -X GET "https://api.aisa.one/apis/v1/youtube/search?engine=youtube&q=python+tutorial&sp=EgIQAQ%3D%3D" \ -H "Authorization: Bearer $AISA_API_KEY"
The API returns structured YouTube search results including video metadata, channel info, thumbnails, and pagination tokens.Note: The response structure may vary by query language. English queries typically return results in the videos array. Some non-English queries may return results grouped in a sections array instead. Always check for both fields.
# Handle both response structuresvideos = results.get('videos', [])if not videos and 'sections' in results: for section in results['sections']: videos.extend(section.get('videos', []))
Note:urllib may encounter 403 errors due to its default User-Agent. Using requests (above) is recommended. If you must use urllib, always set a custom User-Agent header.
import urllib.request, urllib.parse, os, jsondef youtube_search(query, gl=None, hl=None, sp=None): """Search YouTube via AIsa API.""" params = {'engine': 'youtube', 'q': query} if gl: params['gl'] = gl if hl: params['hl'] = hl if sp: params['sp'] = sp url = f'https://api.aisa.one/apis/v1/youtube/search?{urllib.parse.urlencode(params)}' req = urllib.request.Request(url) req.add_header('Authorization', f'Bearer {os.environ["AISA_API_KEY"]}') req.add_header('User-Agent', 'AIsa-Skill/1.0') return json.load(urllib.request.urlopen(req))# Searchresults = youtube_search('OpenClaw tutorial', gl='us', hl='en')# Handle both response formatsvideos = results.get('videos', [])if not videos and 'sections' in results: for section in results['sections']: videos.extend(section.get('videos', []))print(json.dumps(videos[:3], indent=2))
All requests are pay-per-use through your AIsa balance — no separate YouTube API quota management
The engine parameter must always be set to youtube
Video URLs follow the format https://www.youtube.com/watch?v={videoId}
Channel URLs follow the format https://www.youtube.com/channel/{channelId}
Use next_page_token from previous responses as the sp value for pagination
The gl (country) parameter does not support all ISO country codes. Known unsupported values include cn (China). If you get Unsupported value errors, try omitting gl or use a different country code
Non-English queries may return results in a sections array instead of a flat videos array — always handle both formats
IMPORTANT: Python urllib may return 403 errors due to its default User-Agent. Use the requests library instead, or add a custom User-Agent header
IMPORTANT: When using curl commands, ensure environment variables like $AISA_API_KEY are properly expanded
IMPORTANT: When piping curl output to jq, use -s flag and ensure the API key is set