> ## Documentation Index
> Fetch the complete documentation index at: https://docs.incident.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Go SDK

> Call the incident.io API from Go with typed requests and responses for every endpoint.

The Go SDK gives you a typed client for the whole incident.io API. There's a method for every endpoint and a Go type for every request and response, all generated from our OpenAPI specification, so it keeps up with the API without you having to write any of the plumbing yourself.

It requires Go 1.24 or later.

## Installing

```bash theme={null}
go get github.com/incident-io/sdk-go
```

## Your first request

You'll need an API key from **Settings > API keys** (see [API keys](/admin/api-keys)). Then create a client and make a call:

```go theme={null}
package main

import (
	"context"
	"fmt"
	"log"

	incident "github.com/incident-io/sdk-go"
)

func main() {
	c, err := incident.New("my-api-key")
	if err != nil {
		log.Fatal(err)
	}

	resp, err := c.IncidentsV2ListWithResponse(context.Background(), nil)
	if err != nil {
		log.Fatal(err)
	}
	if resp.JSON200 == nil {
		log.Fatalf("unexpected status %d: %s", resp.StatusCode(), resp.Body)
	}

	for _, inc := range resp.JSON200.Incidents {
		fmt.Printf("%s %s\n", inc.Reference, inc.Name)
	}
}
```

## How responses work

Every endpoint has a `...WithResponse` method that returns a typed response. Rather than returning an error for a non-2xx status, the response carries a field per documented status code: `JSON200` for a successful list, `JSON404` for a not-found, and so on. If `JSON200` is `nil`, the API returned something other than a success, and `resp.StatusCode()` and `resp.Body` tell you what.

The `err` return is for failures that never got a response, like a network error or a cancelled context.

## Configuration

`New` takes functional options, so you only set what you need:

```go theme={null}
c, err := incident.New("my-api-key",
	incident.WithUserAgent("my-app/1.0.0"),          // identify your integration
	incident.WithRetries(),                          // opt in to automatic retries
	incident.WithBaseURL("https://api.incident.io"), // override the base URL
	incident.WithHTTPClient(myHTTPClient),           // bring your own HTTP client
)
```

### Retries

By default the client makes a single attempt per request. `WithRetries()` turns on exponential backoff for network errors, `429`s, and `5xx`s, and it honours the `Retry-After` header the API sends when you hit the [rate limit](/api-reference/introduction#rate-limits). `WithRetries(n)` caps the number of retries (the default is 4).

One thing to watch out for: `WithRetries` works by installing its own HTTP client, so combining it with `WithHTTPClient` doesn't do what you'd expect. Whichever option comes last wins.

## Deprecated endpoints

Endpoints we've deprecated stay available, but they're marked with `// Deprecated:`, so your editor and `staticcheck` will flag any calls to them. Don't go by the version in the name: some `v2` endpoints are deprecated too.

## Versioning

The SDK is kept up to date with the API automatically, with each update released as a new minor version.

Go handles major versions differently from other languages: a new major version of a Go module has a different import path (`github.com/incident-io/sdk-go/v2`), and every caller has to change their imports to upgrade. To avoid that, the Go SDK only releases minor versions, which means a change that only affects Go names, like a field being removed from a response, can arrive in a minor release. If you depend on a field, check the [API changelog](/api-reference/changelog) when upgrading.

## Resources

<CardGroup cols={2}>
  <Card title="Package reference" icon="golang" href="https://pkg.go.dev/github.com/incident-io/sdk-go">
    Every type and method on pkg.go.dev.
  </Card>

  <Card title="GitHub" icon="github" href="https://github.com/incident-io/sdk-go">
    Source, README, and issues for the Go SDK.
  </Card>

  <Card title="API reference" icon="code" href="/api-reference/introduction">
    Endpoints, authentication, rate limits, and errors.
  </Card>

  <Card title="All SDKs" icon="cubes" href="/integrations/sdks">
    Clients for TypeScript, Python, Rust, Ruby, PHP, and .NET.
  </Card>
</CardGroup>
