Browse documentation
Get started
Install the Go SDK and run a typed Google Search request. Then try YouTube data with the same client.
Install the SDK
Requires Go 1.25+. Choose a new project or install in the directory containing your existing go.mod.
Installmkdir flashdata-demo cd flashdata-demo go mod init example.com/flashdata-demo go get github.com/flashdatadev/[email protected]Installgo get github.com/flashdatadev/[email protected]Authenticate
Sign up, verify your email and create an API key with Google Search permission, or reuse an authorized key.
Set FLASHDATA_API_KEY below, or keep the value already supplied by your environment. The example reads it explicitly; .env files are not loaded.
Hidden key prompt · Bash# Bash: paste the key into a hidden prompt, not into this command. read -r -s -p "FlashData API key: " FLASHDATA_API_KEY printf '\n' export FLASHDATA_API_KEYHidden key prompt · PowerShell# PowerShell 7: paste the key into a hidden prompt. $flashdataSecureKey = Read-Host "FlashData API key" -AsSecureString $env:FLASHDATA_API_KEY = [System.Net.NetworkCredential]::new("", $flashdataSecureKey).Password Remove-Variable flashdataSecureKeyRun a search
Save this as main.go beside go.mod, then run it in the same terminal. It sends one search for up to five results and prints the JSON response.
main.gopackage main import ( "context" "encoding/json" "log" "os" "time" flashdata "github.com/flashdatadev/flashdata-go" ) func main() { key := os.Getenv("FLASHDATA_API_KEY") if key == "" { log.Fatal("Set FLASHDATA_API_KEY through your server's secret manager.") } client, err := flashdata.New(flashdata.Options{APIKey: key}) if err != nil { log.Fatal(err) } ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute) defer cancel() result, err := client.Google.Search(ctx, flashdata.GoogleSearchInput{ Query: "battery recycling research", Params: &flashdata.GoogleSearchParams{Num: flashdata.Ptr(int64(5))}, }) if err != nil { // Do not automatically resubmit an uncertain paid request. log.Fatal(err) } if err := json.NewEncoder(os.Stdout).Encode(result); err != nil { log.Fatal(err) } if result.Status != "done" { log.Fatalf("Search did not complete: %s", result.Status) } }Rungo run .Check the result
Look for status: done in the printed JSON. Use the returned titles, URLs and snippets in your application or agent. An empty organic list is also a valid result.
Example output{ "status": "done", "results": [ { "organic": [ { "title": "Battery recycling research", "link": "https://example.org/recycling", "snippet": "An example search excerpt." } ] } ], "usage": { "credits": 0.02 } }status- done means the search completed.
results[].organic[]- Search results with title, link and snippet fields.
usage.credits- Credits used by this request. Five results are one search, not five requests.
Try another data source
In main.go, replace only the result, err := client.Google.Search(...) call with one of these calls. Keep the client, context, error checks and JSON output, then run go run . again. Each run submits one new request.
Requires google_news permission. Returns news results for your query.
result, err := client.Google.News(ctx, flashdata.GoogleNewsInput{
Query: "battery recycling",
})Requires youtube_metadata permission. Returns video details such as title, channel and duration; it does not download the video.
result, err := client.YouTube.Metadata(ctx, flashdata.YouTubeMetadataInput{
VideoID: "dQw4w9WgXcQ",
})Requires youtube_transcript permission. Requests an existing English transcript, including automatic tracks. Returns text and timestamps when that track is available.
result, err := client.YouTube.Transcript(ctx, flashdata.YouTubeTranscriptInput{
VideoID: "dQw4w9WgXcQ",
Params: &flashdata.YouTubeTranscriptParams{
Language: flashdata.Ptr("en"),
Auto: flashdata.Ptr(true),
},
})What the Go SDK supports
Google- Search, News, Images, Shopping, Videos and Places. Use Google.Pages for paginated results.
YouTube- Search, Metadata, Transcript, Captions, Channel and Suggestions provide structured video data.
YouTube.Download- Submit an audio or video delivery job to your cloud storage. Requires youtube_download permission and storage configuration; use the complete example below.
Jobs / Bulk- Submit with an Async helper, save the job ID, then use Jobs.Wait and Jobs.Result. Bulk handles larger datasets and resumable jobs.
Account- Read identity, balance, pricing, limits and usage before unattended work. Reuse the same client and authorized key.
WithFormat- Request JSON, plain text or Markdown with explicit format options. Markdown formats retrieved data for your agent; your application supplies model calls or summaries.
Go types
GoogleSearchInput describes the query. Optional parameters use pointers, such as flashdata.Ptr(int64(5)). Results contains source JSON; use DecodeResults[GoogleSearchPayload] when you need typed fields.
Next steps
If a step fails
- Package or runtime missing
- Check go version and run go get in the directory containing go.mod.
- 401 / FLASHDATA_API_KEY
- Set a valid key in the terminal where you run the example.
- 403
- Enable Google Search for this API key.
- 402
- Check Billing for available credits, or claim an exhausted agent trial.
- 429
- Wait for Retry-After, then reduce your request rate.
- Timeout or server error
- Check History before resending; the first request may already have run.