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

# Error Handling

> Handle errors in the Reducto Go SDK

The Reducto Go SDK uses standard Go error handling patterns with a specific `*reducto.Error` type for API errors.

***

## Error Handling

All SDK methods return errors following Go conventions:

```go theme={null}
result, err := client.Parse.Run(context.Background(), params)
if err != nil {
    // Handle error
    fmt.Printf("Error: %v\n", err)
    return
}
// Use result...
```

***

## API Error Type

When the API returns a non-success status code, the SDK returns a `*reducto.Error`:

```go theme={null}
import (
    "errors"
    reducto "github.com/reductoai/reducto-go-sdk"
)

result, err := client.Parse.Run(context.Background(), params)
if err != nil {
    var apierr *reducto.Error
    if errors.As(err, &apierr) {
        // Access error details
        fmt.Printf("Status Code: %d\n", apierr.StatusCode)
        fmt.Printf("Request: %s\n", string(apierr.DumpRequest(true)))
        fmt.Printf("Response: %s\n", string(apierr.DumpResponse(true)))
    }
    return err
}
```

The `*reducto.Error` type contains:

* `StatusCode`: HTTP status code
* `*http.Request`: The request that failed
* `*http.Response`: The response received
* `DumpRequest()`: Serialize the HTTP request for debugging
* `DumpResponse()`: Serialize the HTTP response for debugging

***

## Error Status Codes

Common status codes:

* `400`: Bad Request - Invalid parameters
* `401`: Authentication Error - Invalid or missing API key
* `403`: Permission Denied - Insufficient permissions
* `404`: Not Found - Resource doesn't exist
* `422`: Unprocessable Entity - Validation error
* `429`: Rate Limit - Too many requests
* `500+`: Internal Server Error - Server-side issue

***

## Automatic Retries

The SDK automatically retries requests on:

* Connection errors
* 408 Request Timeout
* 409 Conflict
* 429 Rate Limit
* 5xx Internal Server Errors

Default retry count is 2, configurable via `option.WithMaxRetries`:

```go theme={null}
// Configure default retries for all requests
client := reducto.NewClient(
    option.WithAPIKey(os.Getenv("REDUCTO_API_KEY")),
    option.WithMaxRetries(5), // default is 2
)

// Or per-request
result, err := client.Parse.Run(
    context.Background(),
    params,
    option.WithMaxRetries(3),
)
```

***

## Manual Retry Logic

For custom retry logic:

```go theme={null}
import "time"

func parseWithRetry(client *reducto.Client, params reducto.ParseRunParams, maxRetries int) (*shared.ParseResponse, error) {
    var lastErr error
    for i := 0; i < maxRetries; i++ {
        result, err := client.Parse.Run(context.Background(), params)
        if err == nil {
            return result, nil
        }
        lastErr = err
        
        // Exponential backoff
        time.Sleep(time.Duration(1<<uint(i)) * time.Second)
    }
    return nil, lastErr
}
```

***

## Timeouts

Use context for request timeouts:

```go theme={null}
// Set timeout for entire request lifecycle (including retries)
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute)
defer cancel()

result, err := client.Parse.Run(ctx, params)

// Set per-retry timeout
result, err := client.Parse.Run(
    context.Background(),
    params,
    option.WithRequestTimeout(20*time.Second),
)
```

***

## Next Steps

* Learn about [job management](/sdk/go/job-management) for async operations
* Explore the [Go SDK overview](/sdk/go/overview) for usage patterns
