Memory

go-perplexity

Try it

Unofficial Go client for the Perplexity REST API at https://api.perplexity.ai. Package perplexity (github.com/psyb0t/go-perplexity), generated with oapi-codegen from Perplexity's OpenAPI document, has one typed method per endpoint on the client from perplexity.NewClientWithResponses, covering Sonar chat completions (sync and async), web search, embeddings and contextualized embeddings, agents and their files, skills, decisions, models and usage analytics, with JSON bodies decoded into Go structs. Auth is a bearer API key set through a request editor. Use when Go code needs to call the Perplexity API or already imports go-perplexity.

What it does

Typed Go client for the Perplexity API. Every endpoint in Perplexity's OpenAPI document is a method on .

The skill document

go-perplexity

Typed Go client for the Perplexity API. Every endpoint in Perplexity's OpenAPI document is a method on ClientWithResponses.

For install, the method list, union types and error handling, see references/setup.md.

Security & safety

  • Read the API key from an environment variable such as PERPLEXITY_API_KEY. Never hardcode it, commit it or log it, and never print request headers.
  • Requests go only to the base URL passed to NewClientWithResponses. Use https://api.perplexity.ai.
  • Calls cost money and some change account state (creating, updating and deleting skills, creating and cancelling agent runs). Make those calls only when the user asked for them, and only on resources the task created or named.

When to use

  • Go code needs Sonar answers with citations, Perplexity web search, embeddings or another Perplexity endpoint.
  • The project already imports github.com/psyb0t/go-perplexity.

When NOT to use

  • The code is not Go.
  • You need streaming. The generated methods read the whole response body; for server-sent events, use the plain Client method, which returns the *http.Response with the body unread, and parse the stream yourself.

Usage

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

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

auth := perplexity.WithRequestEditorFn(func(_ context.Context, req *http.Request) error {
	req.Header.Set("Authorization", "Bearer "+os.Getenv("PERPLEXITY_API_KEY"))

	return nil
})

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

A Sonar chat completion. Message content is a union, built and read with From... and As... helpers (Content0 is plain text):

var content perplexity.ChatMessageInput_Content
if err := content.FromChatMessageInputContent0("What changed in Go 1.26?"); err != nil {
	return err
}

res, err := client.ChatCompletionsChatCompletionsPostWithResponse(ctx, perplexity.ApiChatCompletionsRequest{
	Model: perplexity.ApiChatCompletionsRequestModelSonar,
	Messages: []perplexity.ChatMessageInput{{
		Content: &content,
		Role:    perplexity.ChatMessageRoleUser,
	}},
})
if err != nil {
	return err // transport error
}

if res.JSON200 == nil {
	return fmt.Errorf("sonar: status %d: %s", res.StatusCode(), res.Body)
}

for _, choice := range res.JSON200.Choices {
	if choice.Message.Content == nil {
		continue
	}

	text, err := choice.Message.Content.AsChatMessageOutputContent0()
	if err == nil {
		fmt.Println(text)
	}
}

A web search:

var query perplexity.ApiSearchRequest_Query
if err := query.FromApiSearchRequestQuery0("go generics tutorial"); err != nil {
	return err
}

maxResults := 5

found, err := client.SearchSearchPostWithResponse(ctx, perplexity.ApiSearchRequest{
	Query:      query,
	MaxResults: &maxResults,
})
if err != nil {
	return err
}

if found.JSON200 == nil {
	return fmt.Errorf("search: status %d: %s", found.StatusCode(), found.Body)
}

for _, page := range found.JSON200.Results {
	fmt.Println(page.Title, page.Url)
}

Related skills

Join a video meeting as an AI bot with voice, avatar, and screenshare across four operating modes.

by johnpatternai22 installs8 stars

Stores durable facts in a categorized, plain-markdown vault on disk, alongside your agent's built-in memory.

by Iván561 installs18 stars

Find why your productivity system keeps failing, then apply the smallest fix — capacity math, bottleneck routing, durable local notes.

by Iván857 installs69 stars

Generate and edit Draw.io, Mermaid, and Excalidraw diagrams from natural language using a structured JSON spec.

by nssa.io1.0k installs47 stars

Fetch raw ad creative, app, ranking, and revenue data from AdMapix as structured JSON.

by fly0pants4.3k installs296 stars

More from psyb0t

Browse all skills

Drive a user-deployed mt5-httpapi MetaTrader 5 bridge over HTTP, with per-action confirmation on every real-money call.

by psyb0t108 installs4 stars

Docker-packaged browser automation for QA against anti-bot stacks and authorized detection testing.

by psyb0t138 installs2 stars

Self-hosted OpenAI-compatible speech service — transcription, translation, and synthesis from one container.

by psyb0t13 installs

Run ffmpeg, sox, and ImageMagick jobs against your files in a fixed-allowlist SSH sandbox.

by psyb0t71 installs

Generate speech audio via Qwen3-TTS over SSH with preset voices, voice cloning, and voice design.

by psyb0t55 installs

Drive one or more IMAP/SMTP mailboxes through a single REST + MCP endpoint — read, search, send, mark-seen, and delete across accounts in parallel.

by psyb0t15 installs