360 Secure SkillHub
360 安全技能中心

go-exa

提供非官方 go-exa 客户端的安装与用法说明,指导在 Go 代码中调用 Exa 的搜索、相似页面、页面内容、带引用答案、Agent 运行与 Websets 接口,并给出认证方式、响应解析和错误处理示例。

分类:开发
psyb0t
psyb0t
热度 14.29
最近更新 2026-11-20 07:35:13

安装

发给 Agent
帮我安装这个技能:npx secure-skills-cli add psyb0t/go-exa
兼容性
通用兼容
联网要求
需要联网
数据出网
必须出网
Metadata
name
go-exa
description
Use the unofficial go-exa client for web search, page contents, cited answers, agent runs and Websets in Go. Applies when adding Exa integration or working with an existing github.com/psyb0t/go-exa import.
license
MIT
homepage
https://github.com/psyb0t/go-exa
user-invocable
true
metadata
{"openclaw":{"emoji":"🔎","requires":{"bins":["go"]}}}
permissions
{"filesystem":"Guides edits to the Go source of the current project. The library reads and writes no files.","shell":"The Go toolchain (`go get`, `go build`, `go test`) to add and compile the dependency.","network":"`go get` fetches the module from your Go module proxy. At runtime the code you write talks HTTPS to api.exa.ai only."}

go-exa

Unofficial, typed Go client for the Exa search API, in package exa at the module root.

For install, every operation, request options and response fields, see references/setup.md.

Security & safety

  • Exa authenticates with an API key in the x-api-key header. Read it from the EXA_API_KEY environment variable. Never hardcode, commit or log it, and never print a request with its headers.
  • Requests go only to https://api.exa.ai. Search queries, URLs and answer prompts you send leave the machine for Exa, so do not put secrets or private data in them.
  • Calls can incur charges on the key's account; cost fields vary by endpoint. Agent runs can run long and cost more, so start them only when the user asked.

When to use

  • Go code needs web search results, similar pages, page text or highlights, or an answer with citations.
  • The project already imports github.com/psyb0t/go-exa.

When NOT to use

  • The code is not Go. This module ships only a Go package.
  • You need a client maintained by Exa. This one is unofficial and not affiliated with Exa.
  • You want to change the generated client itself. See AGENTS.md in the repo.

Finding endpoints and types

The examples below cover a few calls. Every operation in the spec has a generated method, and the spec's descriptions are on them as Go doc comments. Look names and fields up instead of guessing. After go get github.com/psyb0t/go-exa, from inside your module:

go doc github.com/psyb0t/go-exa ClientWithResponsesInterface  # every endpoint method
go doc github.com/psyb0t/go-exa SearchJSONRequestBody         # one method, params type or model
go doc -all github.com/psyb0t/go-exa                          # the whole package

The same documentation is at https://pkg.go.dev/github.com/psyb0t/go-exa.

Method names come from the spec's operation IDs. <OperationId>WithResponse takes the context, then the path parameters in order, then *<OperationId>Params when the operation has query or header parameters, then the request body when it has one. The JSON200 field (or JSON201 and so on, per declared status) holds the decoded body; it is nil for any other status. Response wrappers that share a name with a schema get a 2 suffix, as described under Usage.

Usage

import (
	"context"
	"fmt"
	"net/http"
	"os"

	exa "github.com/psyb0t/go-exa"
)

auth := exa.WithRequestEditorFn(
	func(_ context.Context, req *http.Request) error {
		req.Header.Set("x-api-key", os.Getenv("EXA_API_KEY"))

		return nil
	},
)

client, err := exa.NewClientWithResponses("https://api.exa.ai", auth)
if err != nil {
	return err
}

numResults := 5

search, err := client.SearchWithResponse(ctx, exa.SearchJSONRequestBody{
	Query:          "open source vector databases",
	NumResults:     &numResults,
	IncludeDomains: &[]string{"github.com"},
})
if err != nil {
	return err // transport failure
}

if search.JSON200 == nil {
	return fmt.Errorf("search: %s", search.Status())
}

results, err := search.JSON200.AsSearchResultsResponse()
if err != nil {
	return err
}

for _, result := range results.Results {
	fmt.Println(result.Url)
}

answer, err := client.AnswerWithResponse(ctx, exa.AnswerJSONRequestBody{
	Query: "What is the boiling point of water at sea level?",
})
if err != nil {
	return err
}

if answer.JSON200 != nil {
	text, err := answer.JSON200.Answer.AsAnswerResponseAnswer0() // string
	if err == nil {
		fmt.Println(text)
	}
}

Most response fields are pointers; check for nil before dereferencing. The error return covers only transport and decoding failures. An API error comes back with JSON200 nil: check StatusCode() and Body.

Response wrappers that share a name with a schema get a 2 suffix: SearchWithResponse returns *exa.SearchResponse2, whose JSON200 is the *exa.SearchResponse schema.