Skip to main content
The Reducto Go SDK provides a strongly-typed interface to the Reducto API. It handles authentication, request formatting, and response parsing automatically.
The Go SDK is in alpha (v0.1.0-alpha.1). Edit and Pipeline endpoints are not yet supported. Use the REST API directly for those features.

Quick Start

package main

import (
    "context"
    "fmt"
    "io"
    "os"

    reducto "github.com/reductoai/reducto-go-sdk"
    "github.com/reductoai/reducto-go-sdk/option"
    "github.com/reductoai/reducto-go-sdk/shared"
)

func main() {
    // Initialize the client (reads REDUCTO_API_KEY from environment)
    client := reducto.NewClient(option.WithAPIKey(os.Getenv("REDUCTO_API_KEY")))

    // Upload a document
    file, _ := os.Open("invoice.pdf")
    defer file.Close()
    
    upload, _ := client.Upload(context.Background(), reducto.UploadParams{
        File: reducto.F[io.Reader](file),
    })

    // Parse the document
    result, _ := client.Parse.Run(context.Background(), reducto.ParseRunParams{
        ParseConfig: reducto.ParseConfigParam{
            DocumentURL: reducto.F[reducto.ParseConfigDocumentURLUnionParam](
                shared.UnionString(upload.FileID),
            ),
        },
    })

    // Access the extracted content using union type
    if result.Result.Type == shared.ParseResponseResultTypeFull {
        fullResult := result.Result.AsUnion().(shared.ParseResponseResultFullResult)
        for _, chunk := range fullResult.Chunks {
            fmt.Println(chunk.Content)
        }
    }
}

Key Features

Strong Typing

Full type safety with Goโ€™s type system and generated types for all API responses.

Context Support

All methods accept context.Context for cancellation and timeouts.

Error Handling

Standard Go error handling with detailed error types.

Concurrent Safe

Client instances are safe for concurrent use.

Installation

go get github.com/reductoai/reducto-go-sdk
Requires Go 1.18+. The SDK requires no additional dependencies.

Authentication

Set your API key as an environment variable:
export REDUCTO_API_KEY="your_api_key_here"
The SDK reads it automatically:
import (
    "os"
    reducto "github.com/reductoai/reducto-go-sdk"
    "github.com/reductoai/reducto-go-sdk/option"
)

// Recommended: pass explicitly for clarity
client := reducto.NewClient(option.WithAPIKey(os.Getenv("REDUCTO_API_KEY")))
Get your API key from Reducto Studio โ†’ API Keys.

Core Methods

The SDK provides methods for all Reducto endpoints:

Upload

Upload documents to Reductoโ€™s servers before processing:
upload, err := client.Upload(context.Background(), reducto.UploadParams{
    File: reducto.F[io.Reader](file),
})
// Returns: UploadResponse with FileID field

Upload Documentation

File upload options, size limits, and presigned URLs.

Parse

Convert documents into structured JSON with text, tables, and figures:
result, err := client.Parse.Run(context.Background(), reducto.ParseRunParams{
    ParseConfig: reducto.ParseConfigParam{
        DocumentURL: reducto.F[reducto.ParseConfigDocumentURLUnionParam](
            shared.UnionString(upload.FileID),
        ),
    },
})

Parse Documentation

Parse configuration, chunking options, and response structure.

Extract

Pull specific fields from documents using JSON schemas:
result, err := client.Extract.Run(context.Background(), reducto.ExtractRunParams{
    ExtractConfig: reducto.ExtractConfigParam{
        DocumentURL: reducto.F[reducto.ExtractConfigDocumentURLUnionParam](
            shared.UnionString(upload.FileID),
        ),
        Schema: reducto.F[interface{}](schema),
    },
})

Extract Documentation

Schema design, array extraction, and citations.

Split

Divide documents into sections based on content descriptions:
result, err := client.Split.Run(context.Background(), reducto.SplitRunParams{
    DocumentURL: reducto.F[reducto.SplitRunParamsDocumentURLUnion](
        shared.UnionString(upload.FileID),
    ),
    SplitDescription: reducto.F([]shared.SplitCategoryParam{
        {Name: reducto.F("Introduction"), Description: reducto.F("Introduction section")},
        {Name: reducto.F("Results"), Description: reducto.F("Results section")},
    }),
})

Split Documentation

Split configuration and section types.

Edit & Pipeline

Edit and Pipeline endpoints are not available in the Go SDK. Use the REST API directly or the clientโ€™s Post method. See Edit and Pipeline pages for workarounds.

Async Jobs

For long-running operations, use RunJob methods to get a job ID:
// Start async job
job, err := client.Parse.RunJob(context.Background(), reducto.ParseRunJobParams{
    DocumentURL: reducto.F[reducto.ParseRunJobParamsDocumentURLUnion](
        shared.UnionString(upload.FileID),
    ),
})
fmt.Println(job.JobID)

// Check status
status, err := client.Job.Get(context.Background(), job.JobID)
if status.Status == "Completed" {
    fmt.Println(status.Result)
}

Async Processing

Concurrent processing with goroutines and async job management.

Type System

The Go SDK uses a strongly-typed system with param.Field wrappers and union types:

Param Fields

All request parameters use param.Field[T] to distinguish zero values from null or omitted fields:
// Wrap values with F[T]()
DocumentURL: reducto.F[reducto.ParseConfigDocumentURLUnionParam](
    shared.UnionString(upload.FileID),
)

// For integers
ChunkSize: reducto.Int(1000)

// For strings
SystemPrompt: reducto.String("Extract financial data")

// For booleans
Enabled: reducto.Bool(true)

Union Types

Response types that can have different structures use union types. Use AsUnion() to cast:
if result.Result.Type == shared.ParseResponseResultTypeFull {
    fullResult := result.Result.AsUnion().(shared.ParseResponseResultFullResult)
    for _, chunk := range fullResult.Chunks {
        // ...
    }
}

Error Handling

The SDK uses standard Go error handling:
result, err := client.Parse.Run(context.Background(), params)
if err != nil {
    fmt.Printf("Error: %v\n", err)
    return
}

Error Handling Guide

Complete error handling reference with all error types.

Next Steps

1

Get your API key

Create an API key in Reducto Studio and set it as REDUCTO_API_KEY.
2

Try the quickstart

Run your first parse operation with the quickstart example.
3

Explore the methods

Check out the core methods documentation for detailed usage.