AI Search API in Go.

Go’s net/http is all AI Search API needs. Capture the answer a real user sees on ChatGPT, Perplexity, Copilot or Google AI and decode the canonical Envelope into your own structs.

Bearer-authenticate, POST to /v1/search, and either block for the Envelope (sync) or take the 202 and poll /v1/jobs/:id. Charged only on a successful capture; 500 free credits to start.

search.go, one surface, inline Envelope
package main

import (
	"bytes"
	"encoding/json"
	"fmt"
	"net/http"
	"os"
)

func main() {
	body, _ := json.Marshal(map[string]any{
		"query":    "best crm for startups",
		"surfaces": []string{"chatgpt"},
	})
	req, _ := http.NewRequest("POST",
		"https://api.aisearchapi.dev/v1/search?mode=sync",
		bytes.NewReader(body))
	req.Header.Set("Authorization", "Bearer "+os.Getenv("AISEARCH_API_KEY"))
	req.Header.Set("Content-Type", "application/json")

	res, err := http.DefaultClient.Do(req)
	if err != nil {
		panic(err)
	}
	defer res.Body.Close()

	var out map[string]any
	json.NewDecoder(res.Body).Decode(&out)
	env := out["children"].([]any)[0].(map[string]any)
	fmt.Println(env["answer"])
}

Fan out across surfaces.

Add more surfaces or regions and the call goes async: a 202 with a jobId, one child capture per (surface × region). Poll /v1/jobs/:id or attach a signed webhook.

The full submit → poll → read round-trip and a webhook receiver are in the docs.

Submit then poll GET /v1/jobs/:id
// Submit with multiple surfaces/regions → 202 + {"jobId": "..."}.
// Then poll until the job status is terminal:
//
//   for {
//       res, _ := http.Get(BASE + "/v1/jobs/" + jobID)  // + Bearer header
//       // decode; break when job.status is terminal
//       //   (completed / partial / failed / canceled / expired)
//       time.Sleep(2 * time.Second)
//   }
//
// Every (surface × region) is one child capture, counted once.

Go + AI Search API, asked precisely.

Is there a Go module?

Not yet. net/http and encoding/json cover the whole contract. Define structs for the Envelope fields you use, or decode into map[string]any to start.

How do I handle the async fan-out in Go?

A multi-surface or multi-region request returns 202 with a jobId. Poll GET /v1/jobs/:id on an interval (or attach a webhook) until the status is terminal (completed, partial, failed, canceled or expired).

Ship it in Go today.

Grab a key, spend 500 free credits on a real fan-out, and read the Envelope back. Charged only on success.

other languages:PythonNode.jsPHPRuby