> ## 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.

# Split

> Split documents into sections using the Go SDK

The `Split.Run()` method divides documents into sections based on descriptions you provide. You define what sections to look for, and Split identifies which pages belong to each section.

<Note>
  The Go SDK (v0.1.0-alpha.1) has a type definition mismatch for Split responses. The `splits` array is returned in the API response but not typed in the SDK. Use the raw JSON to access split results reliably.
</Note>

***

## Basic Usage

```go theme={null}
package main

import (
    "context"
    "encoding/json"
    "fmt"
    "os"
    
    reducto "github.com/reductoai/reducto-go-sdk"
    "github.com/reductoai/reducto-go-sdk/option"
    "github.com/reductoai/reducto-go-sdk/shared"
)

func main() {
    client := reducto.NewClient(option.WithAPIKey(os.Getenv("REDUCTO_API_KEY")))
    
    // Split the document - split_description is required
    result, err := client.Split.Run(context.Background(), reducto.SplitRunParams{
        DocumentURL: reducto.F[reducto.SplitRunParamsDocumentURLUnion](
            shared.UnionString("https://example.com/document.pdf"),
        ),
        SplitDescription: reducto.F([]shared.SplitCategoryParam{
            {
                Name:        reducto.F("Summary"),
                Description: reducto.F("Executive summary or overview section"),
            },
            {
                Name:        reducto.F("Financial Data"),
                Description: reducto.F("Tables with financial figures"),
            },
        }),
    })
    if err != nil {
        fmt.Printf("Split error: %v\n", err)
        return
    }
    
    // Parse raw JSON to access splits (SDK type limitation workaround)
    var splitResult struct {
        Splits []struct {
            Name       string  `json:"name"`
            Pages      []int64 `json:"pages"`
            Conf       string  `json:"conf"`
            Partitions []interface{} `json:"partitions"`
        } `json:"splits"`
    }
    
    rawJSON := result.JSON.RawJSON()
    // Extract the result portion
    var fullResult map[string]json.RawMessage
    json.Unmarshal([]byte(rawJSON), &fullResult)
    json.Unmarshal(fullResult["result"], &splitResult)
    
    // Access splits
    for _, split := range splitResult.Splits {
        fmt.Printf("Section: %s\n", split.Name)
        fmt.Printf("Pages: %v\n", split.Pages)
        fmt.Printf("Confidence: %s\n", split.Conf)
    }
}
```

***

## Method Signatures

### Synchronous Split

```go theme={null}
func (s *SplitService) Run(
    ctx context.Context,
    body SplitRunParams,
    opts ...option.RequestOption,
) (*shared.SplitResponse, error)
```

### Asynchronous Split

```go theme={null}
func (s *SplitService) RunJob(
    ctx context.Context,
    body SplitRunJobParams,
    opts ...option.RequestOption,
) (*SplitRunJobResponse, error)
```

***

## Parameters

### SplitRunParams

| Field              | Type                                    | Required | Description                                             |
| ------------------ | --------------------------------------- | -------- | ------------------------------------------------------- |
| `DocumentURL`      | `SplitRunParamsDocumentURLUnion`        | Yes      | File URL, `reducto://` file ID, or `jobid://` reference |
| `SplitDescription` | `[]shared.SplitCategoryParam`           | Yes      | List of sections to identify                            |
| `SplitRules`       | `string`                                | No       | Natural language prompt for classification rules        |
| `AdvancedOptions`  | `shared.AdvancedProcessingOptionsParam` | No       | Advanced processing options                             |
| `Options`          | `shared.BaseProcessingOptionsParam`     | No       | Base processing options                                 |

### SplitCategoryParam

Each split category requires:

```go theme={null}
shared.SplitCategoryParam{
    Name:         reducto.F("Section Name"),
    Description:  reducto.F("Description of what this section contains"),
    PartitionKey: reducto.F("optional_partition_key"),  // Optional
}
```

***

## Configuration Examples

### With Partition Key

Use `PartitionKey` when a section type repeats multiple times:

```go theme={null}
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("Invoice"),
            Description:  reducto.F("Individual invoice with line items"),
            PartitionKey: reducto.F("invoice_number"),
        },
    }),
})
```

### With Split Rules

```go theme={null}
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("Summary"), Description: reducto.F("Executive summary")},
        {Name: reducto.F("Details"), Description: reducto.F("Detailed content")},
    }),
    SplitRules: reducto.F("Pages can belong to multiple sections if they contain content from both."),
})
```

***

## Response Structure

Due to SDK type limitations, access the response via raw JSON:

```go theme={null}
// API Response structure (access via raw JSON)
type SplitResult struct {
    Splits []struct {
        Name       string        `json:"name"`       // Section name you defined
        Pages      []int64       `json:"pages"`      // Page numbers (1-indexed)
        Conf       string        `json:"conf"`       // "high" or "low"
        Partitions []interface{} `json:"partitions"` // Sub-sections (if partition_key used)
    } `json:"splits"`
}
```

***

## Error Handling

```go theme={null}
result, err := client.Split.Run(context.Background(), params)
if err != nil {
    fmt.Printf("Split failed: %v\n", err)
    return
}
```

***

## Next Steps

* Learn about [split configuration options](/configs/split/configuration)
* Check out [parsing split sections](/sdk/go/parse) for further processing
