Skip to content
EN
Get API key
Browse documentation

Get started

Go SDK quickstart

Install the Go SDK and run a typed Google Search request. Then try YouTube data with the same client.

  1. Install the SDK

    Requires Go 1.25+. Choose a new project or install in the directory containing your existing go.mod.

    Install
    mkdir flashdata-demo
    cd flashdata-demo
    go mod init example.com/flashdata-demo
    go get github.com/flashdatadev/[email protected]
  2. 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_KEY
  3. Run 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.go
    package 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)
        }
    }
    Run
    go run .
  4. 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.

Replace the search call in main.go
result, err := client.Google.News(ctx, flashdata.GoogleNewsInput{
    Query: "battery recycling",
})

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.