SerpBase
Back to Blog

YouTube Search Filter API: Today, This Week and Long Videos with sp

Pass YouTube's filter codes in sp to search only videos uploaded today or this week, or over 20 minutes. Five codes tested, including one YouTube no longer honours.

November 30, 2026
By SerpBase Team2 min read

Short answer: pass YouTube's own filter code in the sp field of POST /youtube/search. EgIIAg== keeps videos uploaded today, EgIIAw== this week and EgIYAg== videos over 20 minutes. Send the code exactly as shown, not URL-encoded. One request is 1 credit and returns about 20 videos with title, channel, duration, age and view count.

The request

curl -X POST 'https://api.serpbase.dev/youtube/search' \
  -H 'Content-Type: application/json' \
  -H 'X-API-Key: YOUR_API_KEY' \
  -d '{"q":"nextjs tutorial","sp":"EgIIAw=="}'

The url field in the answer shows the YouTube results address that was fetched, with your sp in it, so you can open it in a browser and compare.

Codes we tested on 30 November 2026

spYouTube filterWhat came back
(none)Relevance16 videos, top results 1 to 5 years old
EgIIAw==Upload date: this week20 videos, every one between 4 hours and 6 days old
EgIIAg==Upload date: today20 videos aged 2 to 14 hours, plus 19 Shorts (for "world cup qualifiers highlights")
EgIYAg==Duration: over 20 minutes20 videos, shortest 28:25, longest 8:48:53
EgIQAg==Type: channelchannels instead of videos (see the channel search guide below)
CAI=Old "sort by upload date" codesame order as no filter in our run

The last row matters: YouTube no longer honours the old sort code here, so use the upload-date filters when you need recent videos.

What a video looks like

{
  "title": "Navigation in Next.js with Link | Fullstack JS | Lesson 76",
  "link": "https://www.youtube.com/watch?v=bXc9coD5XWo",
  "channel": {
    "title": "MAYKON SILVEIRA",
    "id": "UC4p79Xbb2k1oDVy68nGQIMA"
  },
  "duration": "12:59",
  "published_at": "4h ago",
  "views_count": "14",
  "badges": [
    "New"
  ]
}

published_at is the relative age YouTube prints ("4h ago", "3y ago"). Shorts in the "today" answer had views_count but no published_at or duration, and their link points to /shorts/.

Daily watch for new videos

import requests

def new_videos(query, sp="EgIIAg=="):
    data = requests.post("https://api.serpbase.dev/youtube/search",
                         headers={"X-API-Key": "YOUR_API_KEY"},
                         json={"q": query, "sp": sp}, timeout=60).json()
    if data["status"] != 0:
        raise RuntimeError(data.get("error"))
    return [v for v in data.get("videos", []) if "/shorts/" not in v["link"]]

for v in new_videos("world cup qualifiers highlights"):
    print(v.get("published_at"), v.get("duration"), v["title"][:70])

Things that trip people up

  • Do not URL-encode sp. Send EgIIAw==, not EgIIAw%3D%3D; the API encodes it for you, so an already-encoded value ends up encoded twice in the url field.
  • Shorts arrive mixed in. Filter on /shorts/ in the link if you only want regular videos.
  • Ages are relative. Convert "4h ago" against the time you made the request, not the time you process it.

Related

YouTube search basics: YouTube search API without quota. Captions for a video: YouTube transcript API. Finding channels: YouTube channel search API.

Cost and docs

YouTube searches are 1 credit. Credits cost $0.25–$0.50 per 1,000 depending on the plan; new accounts get 500 free credits.