---
title: Go
description: A typed, context-aware client for the Firmreader API
---

> **For AI agents:** the complete documentation index is at [llms.txt](/llms.txt). Append `.md` to any page URL for its markdown version.

The Go SDK requires Go 1.21+. Every method takes a `context.Context` so you can apply timeouts and cancellation.

## Install

```bash
go get github.com/firmreader/firmreader-go
```

## Initialize the client

```go
package main

import (
	"os"

	"github.com/firmreader/firmreader-go"
)

func main() {
	client := firmreader.NewClient(os.Getenv("FIRMREADER_API_KEY")) // fr_live_...
	_ = client
}
```

## Create a post

```go
post, err := client.Posts.Create(ctx, &firmreader.PostParams{
	ChannelID: "ch_company_news",
	Title:     "Welcome to Firmreader",
	Body:      "We're excited to announce our new internal communications platform.",
	Priority:  "normal",
})
if err != nil {
	log.Fatal(err)
}

fmt.Printf("Published post %s\n", post.ID)
```

## List posts

```go
posts, err := client.Posts.List(ctx, &firmreader.ListParams{
	ChannelID: "ch_company_news",
	Limit:     20,
})
if err != nil {
	log.Fatal(err)
}

for _, post := range posts.Data {
	fmt.Println(post.Title)
}
```

## Handle errors

The client returns a `*firmreader.Error` for non-2xx responses. Use `errors.As` to read the status and code.

```go
var apiErr *firmreader.Error
if errors.As(err, &apiErr) {
	fmt.Printf("%d: %s\n", apiErr.Status, apiErr.Code)
}
```

<Note>
Set `firmreader.WithIdempotencyKey("...")` on any write call so retries don't create duplicate posts.
</Note>
