Repository navigation
Expand file tree
/
Copy pathsplit.go
More file actions
810 lines (753 loc) · 34 KB
/
Copy pathsplit.go
File metadata and controls
810 lines (753 loc) · 34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
package llamacloud
import (
"context"
"errors"
"fmt"
"net/http"
"net/url"
"slices"
"time"
"github.com/run-llama/llama-parse-go/internal/apijson"
"github.com/run-llama/llama-parse-go/internal/apiquery"
"github.com/run-llama/llama-parse-go/internal/requestconfig"
"github.com/run-llama/llama-parse-go/option"
"github.com/run-llama/llama-parse-go/packages/pagination"
"github.com/run-llama/llama-parse-go/packages/param"
"github.com/run-llama/llama-parse-go/packages/respjson"
)
// SplitService contains methods and other services that help with interacting with
// the llama-cloud API.
//
// Note, unlike clients, this service does not read variables from the environment
// automatically. You should not instantiate this service directly, and instead use
// the [NewSplitService] method instead.
type SplitService struct {
options []option.RequestOption
}
// NewSplitService generates a new service that applies the given options to each
// request. These options are applied after the parent client's options (if there
// is one), and before any request-specific options.
func NewSplitService(opts ...option.RequestOption) (r SplitService) {
r = SplitService{}
r.options = opts
return
}
// Create a split job.
//
// ## Document input
//
// Set `file_input` to a file ID or a completed parse job ID (`pjb-...`). Supplying
// a parse job reuses its output instead of reading the document again.
//
// ## Page selection
//
// `configuration.target_pages` selects which pages of a supplied parse job to
// split (1-based; `1-50`, `1,3,5-7`). Pages are read in ascending document order,
// and each segment's `pages` are the parse job's own page numbers, so segments map
// straight back to the original document. Requires a parse job as `file_input`;
// passing it with a file ID returns 400.
//
// ## Parse settings
//
// `configuration.parse_tier` and `configuration.parse_config_id` control how the
// document is read before splitting; both are ignored when a parse job is
// supplied. A parse configuration restricted to a page subset (`target_pages` or
// `max_pages`) is rejected, since split results always number pages relative to
// the full document.
//
// The job runs asynchronously. Poll `GET /split/jobs/{split_job_id}` or register a
// webhook to monitor completion.
func (r *SplitService) New(ctx context.Context, params SplitNewParams, opts ...option.RequestOption) (res *SplitNewResponse, err error) {
opts = slices.Concat(r.options, opts)
path := "api/v1/split/jobs"
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, params, &res, opts...)
return res, err
}
// List document split jobs.
func (r *SplitService) List(ctx context.Context, query SplitListParams, opts ...option.RequestOption) (res *pagination.PaginatedCursor[SplitListResponse], err error) {
var raw *http.Response
opts = slices.Concat(r.options, opts)
opts = append([]option.RequestOption{option.WithResponseInto(&raw)}, opts...)
path := "api/v1/split/jobs"
cfg, err := requestconfig.NewRequestConfig(ctx, http.MethodGet, path, query, &res, opts...)
if err != nil {
return nil, err
}
err = cfg.Execute()
if err != nil {
return nil, err
}
res.SetPageConfig(cfg, raw)
return res, nil
}
// List document split jobs.
func (r *SplitService) ListAutoPaging(ctx context.Context, query SplitListParams, opts ...option.RequestOption) *pagination.PaginatedCursorAutoPager[SplitListResponse] {
return pagination.NewPaginatedCursorAutoPager(r.List(ctx, query, opts...))
}
// Delete a split job and its results. A job that is not in a terminal state is
// refused with 409; cancel it first.
func (r *SplitService) Delete(ctx context.Context, splitJobID string, body SplitDeleteParams, opts ...option.RequestOption) (res *SplitDeleteResponse, err error) {
opts = slices.Concat(r.options, opts)
if splitJobID == "" {
err = errors.New("missing required split_job_id parameter")
return nil, err
}
path := fmt.Sprintf("api/v1/split/jobs/%s", url.PathEscape(splitJobID))
err = requestconfig.ExecuteNewRequest(ctx, http.MethodDelete, path, body, &res, opts...)
return res, err
}
// Cancel a running split job.
//
// Requests cancellation; the job transitions to CANCELLED asynchronously once
// processing stops. Returns the job, which may still be in its current
// non-terminal state. Jobs already in a terminal state (COMPLETED, FAILED,
// CANCELLED) cannot be cancelled.
func (r *SplitService) Cancel(ctx context.Context, splitJobID string, body SplitCancelParams, opts ...option.RequestOption) (res *SplitCancelResponse, err error) {
opts = slices.Concat(r.options, opts)
if splitJobID == "" {
err = errors.New("missing required split_job_id parameter")
return nil, err
}
path := fmt.Sprintf("api/v1/split/jobs/%s/cancel", url.PathEscape(splitJobID))
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
return res, err
}
// Get a document split job.
func (r *SplitService) Get(ctx context.Context, splitJobID string, query SplitGetParams, opts ...option.RequestOption) (res *SplitGetResponse, err error) {
opts = slices.Concat(r.options, opts)
if splitJobID == "" {
err = errors.New("missing required split_job_id parameter")
return nil, err
}
path := fmt.Sprintf("api/v1/split/jobs/%s", url.PathEscape(splitJobID))
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, query, &res, opts...)
return res, err
}
// A split job.
type SplitNewResponse struct {
// Unique identifier for the split job.
ID string `json:"id" api:"required"`
// Categories used for splitting.
Categories []SplitCategory `json:"categories" api:"required"`
// Whether the input was a file or parse job
//
// Any of "file_id", "parse_job_id", "url".
DocumentInputType SplitNewResponseDocumentInputType `json:"document_input_type" api:"required"`
// File ID or parse job ID
FileInput string `json:"file_input" api:"required"`
// Project this job belongs to.
ProjectID string `json:"project_id" api:"required"`
// Current job status. Valid values are: pending, processing, completed, failed,
// cancelled.
Status string `json:"status" api:"required"`
// User who created this job.
UserID string `json:"user_id" api:"required"`
// Split version used for this job.
Version string `json:"version" api:"required"`
// Split configuration ID used for this job.
ConfigurationID string `json:"configuration_id" api:"nullable"`
// Creation datetime
CreatedAt time.Time `json:"created_at" api:"nullable" format:"date-time"`
// Error message if the job failed.
ErrorMessage string `json:"error_message" api:"nullable"`
// Saved parse configuration ID requested for this job, if any.
ParseConfigID string `json:"parse_config_id" api:"nullable"`
// Parse tier requested for this job, if any.
ParseTier string `json:"parse_tier" api:"nullable"`
// Result of a completed split job.
Result SplitResultResponse `json:"result" api:"nullable"`
// Strategy used for splitting.
SplittingStrategy SplitNewResponseSplittingStrategy `json:"splitting_strategy"`
// Page selection requested for this job, if any.
TargetPages string `json:"target_pages" api:"nullable"`
// Idempotency key scoped to the project, if one was provided.
TransactionID string `json:"transaction_id" api:"nullable"`
// Update datetime
UpdatedAt time.Time `json:"updated_at" api:"nullable" format:"date-time"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
ID respjson.Field
Categories respjson.Field
DocumentInputType respjson.Field
FileInput respjson.Field
ProjectID respjson.Field
Status respjson.Field
UserID respjson.Field
Version respjson.Field
ConfigurationID respjson.Field
CreatedAt respjson.Field
ErrorMessage respjson.Field
ParseConfigID respjson.Field
ParseTier respjson.Field
Result respjson.Field
SplittingStrategy respjson.Field
TargetPages respjson.Field
TransactionID respjson.Field
UpdatedAt respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r SplitNewResponse) RawJSON() string { return r.JSON.raw }
func (r *SplitNewResponse) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Whether the input was a file or parse job
type SplitNewResponseDocumentInputType string
const (
SplitNewResponseDocumentInputTypeFileID SplitNewResponseDocumentInputType = "file_id"
SplitNewResponseDocumentInputTypeParseJobID SplitNewResponseDocumentInputType = "parse_job_id"
SplitNewResponseDocumentInputTypeURL SplitNewResponseDocumentInputType = "url"
)
// Strategy used for splitting.
type SplitNewResponseSplittingStrategy struct {
// Controls handling of pages that don't match any category. 'include': pages can
// be grouped as 'uncategorized' and included in results. 'forbid': all pages must
// be assigned to a defined category. 'omit': pages can be classified as
// 'uncategorized' but are excluded from results.
//
// Any of "forbid", "include", "omit".
AllowUncategorized string `json:"allow_uncategorized"`
// Free-form guidance for where segment boundaries are placed.
CustomInstructions string `json:"custom_instructions" api:"nullable"`
// Minimum pages per segment. Shorter segments are merged into an adjacent segment;
// 1 disables merging.
MinPagesPerSplit int64 `json:"min_pages_per_split"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
AllowUncategorized respjson.Field
CustomInstructions respjson.Field
MinPagesPerSplit respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r SplitNewResponseSplittingStrategy) RawJSON() string { return r.JSON.raw }
func (r *SplitNewResponseSplittingStrategy) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// A split job.
type SplitListResponse struct {
// Unique identifier for the split job.
ID string `json:"id" api:"required"`
// Categories used for splitting.
Categories []SplitCategory `json:"categories" api:"required"`
// Whether the input was a file or parse job
//
// Any of "file_id", "parse_job_id", "url".
DocumentInputType SplitListResponseDocumentInputType `json:"document_input_type" api:"required"`
// File ID or parse job ID
FileInput string `json:"file_input" api:"required"`
// Project this job belongs to.
ProjectID string `json:"project_id" api:"required"`
// Current job status. Valid values are: pending, processing, completed, failed,
// cancelled.
Status string `json:"status" api:"required"`
// User who created this job.
UserID string `json:"user_id" api:"required"`
// Split version used for this job.
Version string `json:"version" api:"required"`
// Split configuration ID used for this job.
ConfigurationID string `json:"configuration_id" api:"nullable"`
// Creation datetime
CreatedAt time.Time `json:"created_at" api:"nullable" format:"date-time"`
// Error message if the job failed.
ErrorMessage string `json:"error_message" api:"nullable"`
// Saved parse configuration ID requested for this job, if any.
ParseConfigID string `json:"parse_config_id" api:"nullable"`
// Parse tier requested for this job, if any.
ParseTier string `json:"parse_tier" api:"nullable"`
// Result of a completed split job.
Result SplitResultResponse `json:"result" api:"nullable"`
// Strategy used for splitting.
SplittingStrategy SplitListResponseSplittingStrategy `json:"splitting_strategy"`
// Page selection requested for this job, if any.
TargetPages string `json:"target_pages" api:"nullable"`
// Idempotency key scoped to the project, if one was provided.
TransactionID string `json:"transaction_id" api:"nullable"`
// Update datetime
UpdatedAt time.Time `json:"updated_at" api:"nullable" format:"date-time"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
ID respjson.Field
Categories respjson.Field
DocumentInputType respjson.Field
FileInput respjson.Field
ProjectID respjson.Field
Status respjson.Field
UserID respjson.Field
Version respjson.Field
ConfigurationID respjson.Field
CreatedAt respjson.Field
ErrorMessage respjson.Field
ParseConfigID respjson.Field
ParseTier respjson.Field
Result respjson.Field
SplittingStrategy respjson.Field
TargetPages respjson.Field
TransactionID respjson.Field
UpdatedAt respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r SplitListResponse) RawJSON() string { return r.JSON.raw }
func (r *SplitListResponse) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Whether the input was a file or parse job
type SplitListResponseDocumentInputType string
const (
SplitListResponseDocumentInputTypeFileID SplitListResponseDocumentInputType = "file_id"
SplitListResponseDocumentInputTypeParseJobID SplitListResponseDocumentInputType = "parse_job_id"
SplitListResponseDocumentInputTypeURL SplitListResponseDocumentInputType = "url"
)
// Strategy used for splitting.
type SplitListResponseSplittingStrategy struct {
// Controls handling of pages that don't match any category. 'include': pages can
// be grouped as 'uncategorized' and included in results. 'forbid': all pages must
// be assigned to a defined category. 'omit': pages can be classified as
// 'uncategorized' but are excluded from results.
//
// Any of "forbid", "include", "omit".
AllowUncategorized string `json:"allow_uncategorized"`
// Free-form guidance for where segment boundaries are placed.
CustomInstructions string `json:"custom_instructions" api:"nullable"`
// Minimum pages per segment. Shorter segments are merged into an adjacent segment;
// 1 disables merging.
MinPagesPerSplit int64 `json:"min_pages_per_split"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
AllowUncategorized respjson.Field
CustomInstructions respjson.Field
MinPagesPerSplit respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r SplitListResponseSplittingStrategy) RawJSON() string { return r.JSON.raw }
func (r *SplitListResponseSplittingStrategy) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type SplitDeleteResponse = any
// A split job.
type SplitCancelResponse struct {
// Unique identifier for the split job.
ID string `json:"id" api:"required"`
// Categories used for splitting.
Categories []SplitCategory `json:"categories" api:"required"`
// Whether the input was a file or parse job
//
// Any of "file_id", "parse_job_id", "url".
DocumentInputType SplitCancelResponseDocumentInputType `json:"document_input_type" api:"required"`
// File ID or parse job ID
FileInput string `json:"file_input" api:"required"`
// Project this job belongs to.
ProjectID string `json:"project_id" api:"required"`
// Current job status. Valid values are: pending, processing, completed, failed,
// cancelled.
Status string `json:"status" api:"required"`
// User who created this job.
UserID string `json:"user_id" api:"required"`
// Split version used for this job.
Version string `json:"version" api:"required"`
// Split configuration ID used for this job.
ConfigurationID string `json:"configuration_id" api:"nullable"`
// Creation datetime
CreatedAt time.Time `json:"created_at" api:"nullable" format:"date-time"`
// Error message if the job failed.
ErrorMessage string `json:"error_message" api:"nullable"`
// Saved parse configuration ID requested for this job, if any.
ParseConfigID string `json:"parse_config_id" api:"nullable"`
// Parse tier requested for this job, if any.
ParseTier string `json:"parse_tier" api:"nullable"`
// Result of a completed split job.
Result SplitResultResponse `json:"result" api:"nullable"`
// Strategy used for splitting.
SplittingStrategy SplitCancelResponseSplittingStrategy `json:"splitting_strategy"`
// Page selection requested for this job, if any.
TargetPages string `json:"target_pages" api:"nullable"`
// Idempotency key scoped to the project, if one was provided.
TransactionID string `json:"transaction_id" api:"nullable"`
// Update datetime
UpdatedAt time.Time `json:"updated_at" api:"nullable" format:"date-time"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
ID respjson.Field
Categories respjson.Field
DocumentInputType respjson.Field
FileInput respjson.Field
ProjectID respjson.Field
Status respjson.Field
UserID respjson.Field
Version respjson.Field
ConfigurationID respjson.Field
CreatedAt respjson.Field
ErrorMessage respjson.Field
ParseConfigID respjson.Field
ParseTier respjson.Field
Result respjson.Field
SplittingStrategy respjson.Field
TargetPages respjson.Field
TransactionID respjson.Field
UpdatedAt respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r SplitCancelResponse) RawJSON() string { return r.JSON.raw }
func (r *SplitCancelResponse) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Whether the input was a file or parse job
type SplitCancelResponseDocumentInputType string
const (
SplitCancelResponseDocumentInputTypeFileID SplitCancelResponseDocumentInputType = "file_id"
SplitCancelResponseDocumentInputTypeParseJobID SplitCancelResponseDocumentInputType = "parse_job_id"
SplitCancelResponseDocumentInputTypeURL SplitCancelResponseDocumentInputType = "url"
)
// Strategy used for splitting.
type SplitCancelResponseSplittingStrategy struct {
// Controls handling of pages that don't match any category. 'include': pages can
// be grouped as 'uncategorized' and included in results. 'forbid': all pages must
// be assigned to a defined category. 'omit': pages can be classified as
// 'uncategorized' but are excluded from results.
//
// Any of "forbid", "include", "omit".
AllowUncategorized string `json:"allow_uncategorized"`
// Free-form guidance for where segment boundaries are placed.
CustomInstructions string `json:"custom_instructions" api:"nullable"`
// Minimum pages per segment. Shorter segments are merged into an adjacent segment;
// 1 disables merging.
MinPagesPerSplit int64 `json:"min_pages_per_split"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
AllowUncategorized respjson.Field
CustomInstructions respjson.Field
MinPagesPerSplit respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r SplitCancelResponseSplittingStrategy) RawJSON() string { return r.JSON.raw }
func (r *SplitCancelResponseSplittingStrategy) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// A split job.
type SplitGetResponse struct {
// Unique identifier for the split job.
ID string `json:"id" api:"required"`
// Categories used for splitting.
Categories []SplitCategory `json:"categories" api:"required"`
// Whether the input was a file or parse job
//
// Any of "file_id", "parse_job_id", "url".
DocumentInputType SplitGetResponseDocumentInputType `json:"document_input_type" api:"required"`
// File ID or parse job ID
FileInput string `json:"file_input" api:"required"`
// Project this job belongs to.
ProjectID string `json:"project_id" api:"required"`
// Current job status. Valid values are: pending, processing, completed, failed,
// cancelled.
Status string `json:"status" api:"required"`
// User who created this job.
UserID string `json:"user_id" api:"required"`
// Split version used for this job.
Version string `json:"version" api:"required"`
// Split configuration ID used for this job.
ConfigurationID string `json:"configuration_id" api:"nullable"`
// Creation datetime
CreatedAt time.Time `json:"created_at" api:"nullable" format:"date-time"`
// Error message if the job failed.
ErrorMessage string `json:"error_message" api:"nullable"`
// Saved parse configuration ID requested for this job, if any.
ParseConfigID string `json:"parse_config_id" api:"nullable"`
// Parse tier requested for this job, if any.
ParseTier string `json:"parse_tier" api:"nullable"`
// Result of a completed split job.
Result SplitResultResponse `json:"result" api:"nullable"`
// Strategy used for splitting.
SplittingStrategy SplitGetResponseSplittingStrategy `json:"splitting_strategy"`
// Page selection requested for this job, if any.
TargetPages string `json:"target_pages" api:"nullable"`
// Idempotency key scoped to the project, if one was provided.
TransactionID string `json:"transaction_id" api:"nullable"`
// Update datetime
UpdatedAt time.Time `json:"updated_at" api:"nullable" format:"date-time"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
ID respjson.Field
Categories respjson.Field
DocumentInputType respjson.Field
FileInput respjson.Field
ProjectID respjson.Field
Status respjson.Field
UserID respjson.Field
Version respjson.Field
ConfigurationID respjson.Field
CreatedAt respjson.Field
ErrorMessage respjson.Field
ParseConfigID respjson.Field
ParseTier respjson.Field
Result respjson.Field
SplittingStrategy respjson.Field
TargetPages respjson.Field
TransactionID respjson.Field
UpdatedAt respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r SplitGetResponse) RawJSON() string { return r.JSON.raw }
func (r *SplitGetResponse) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Whether the input was a file or parse job
type SplitGetResponseDocumentInputType string
const (
SplitGetResponseDocumentInputTypeFileID SplitGetResponseDocumentInputType = "file_id"
SplitGetResponseDocumentInputTypeParseJobID SplitGetResponseDocumentInputType = "parse_job_id"
SplitGetResponseDocumentInputTypeURL SplitGetResponseDocumentInputType = "url"
)
// Strategy used for splitting.
type SplitGetResponseSplittingStrategy struct {
// Controls handling of pages that don't match any category. 'include': pages can
// be grouped as 'uncategorized' and included in results. 'forbid': all pages must
// be assigned to a defined category. 'omit': pages can be classified as
// 'uncategorized' but are excluded from results.
//
// Any of "forbid", "include", "omit".
AllowUncategorized string `json:"allow_uncategorized"`
// Free-form guidance for where segment boundaries are placed.
CustomInstructions string `json:"custom_instructions" api:"nullable"`
// Minimum pages per segment. Shorter segments are merged into an adjacent segment;
// 1 disables merging.
MinPagesPerSplit int64 `json:"min_pages_per_split"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
AllowUncategorized respjson.Field
CustomInstructions respjson.Field
MinPagesPerSplit respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r SplitGetResponseSplittingStrategy) RawJSON() string { return r.JSON.raw }
func (r *SplitGetResponseSplittingStrategy) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type SplitNewParams struct {
// File ID or parse job ID
FileInput string `json:"file_input" api:"required"`
OrganizationID param.Opt[string] `query:"organization_id,omitzero" format:"uuid" json:"-"`
ProjectID param.Opt[string] `query:"project_id,omitzero" format:"uuid" json:"-"`
// Saved configuration ID
ConfigurationID param.Opt[string] `json:"configuration_id,omitzero"`
// Idempotency key scoped to the project. Reusing a key returns the original job;
// the new request body is ignored.
TransactionID param.Opt[string] `json:"transaction_id,omitzero"`
// Split configuration with categories and splitting strategy.
Configuration SplitNewParamsConfiguration `json:"configuration,omitzero"`
// IDs of saved webhook configurations to notify for this job.
WebhookConfigurationIDs []string `json:"webhook_configuration_ids,omitzero"`
// Outbound webhook endpoints to notify on job status changes
WebhookConfigurations []SplitNewParamsWebhookConfiguration `json:"webhook_configurations,omitzero"`
paramObj
}
func (r SplitNewParams) MarshalJSON() (data []byte, err error) {
type shadow SplitNewParams
return param.MarshalObject(r, (*shadow)(&r))
}
func (r *SplitNewParams) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// URLQuery serializes [SplitNewParams]'s query parameters as `url.Values`.
func (r SplitNewParams) URLQuery() (v url.Values, err error) {
return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
ArrayFormat: apiquery.ArrayQueryFormatRepeat,
NestedFormat: apiquery.NestedQueryFormatBrackets,
})
}
// Split configuration with categories and splitting strategy.
//
// The property Categories is required.
type SplitNewParamsConfiguration struct {
// Categories to split documents into.
Categories []SplitCategoryParam `json:"categories,omitzero" api:"required"`
// Saved parse configuration ID to control how the document is parsed before
// splitting. Takes precedence over parse_tier. Configurations that restrict pages
// (`target_pages` or `max_pages` on the parse configuration) are rejected: split
// results number pages relative to the full document. Ignored when a completed
// parse job is supplied as file_input.
ParseConfigID param.Opt[string] `json:"parse_config_id,omitzero"`
// Comma-separated page numbers or ranges to split (1-based). Pages are split in
// the order listed. Omit to split all pages. Requires a completed parse job as
// file_input.
TargetPages param.Opt[string] `json:"target_pages,omitzero"`
// Split version to run. Omit for the current release. Preview versions are
// selectable by name and never resolved automatically.
Version param.Opt[string] `json:"version,omitzero"`
// Parse tier used to read the document before splitting. Defaults to fast. Ignored
// when a completed parse job is supplied as file_input.
//
// Any of "agentic", "agentic_plus", "cost_effective", "fast".
ParseTier string `json:"parse_tier,omitzero"`
// Strategy for splitting documents.
SplittingStrategy SplitNewParamsConfigurationSplittingStrategy `json:"splitting_strategy,omitzero"`
paramObj
}
func (r SplitNewParamsConfiguration) MarshalJSON() (data []byte, err error) {
type shadow SplitNewParamsConfiguration
return param.MarshalObject(r, (*shadow)(&r))
}
func (r *SplitNewParamsConfiguration) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
func init() {
apijson.RegisterFieldValidator[SplitNewParamsConfiguration](
"parse_tier", "agentic", "agentic_plus", "cost_effective", "fast",
)
}
// Strategy for splitting documents.
type SplitNewParamsConfigurationSplittingStrategy struct {
// Free-form guidance for where segment boundaries are placed.
CustomInstructions param.Opt[string] `json:"custom_instructions,omitzero"`
// Minimum pages per segment. Shorter segments are merged into an adjacent segment;
// 1 disables merging.
MinPagesPerSplit param.Opt[int64] `json:"min_pages_per_split,omitzero"`
// Controls handling of pages that don't match any category. 'include': pages can
// be grouped as 'uncategorized' and included in results. 'forbid': all pages must
// be assigned to a defined category. 'omit': pages can be classified as
// 'uncategorized' but are excluded from results.
//
// Any of "forbid", "include", "omit".
AllowUncategorized string `json:"allow_uncategorized,omitzero"`
paramObj
}
func (r SplitNewParamsConfigurationSplittingStrategy) MarshalJSON() (data []byte, err error) {
type shadow SplitNewParamsConfigurationSplittingStrategy
return param.MarshalObject(r, (*shadow)(&r))
}
func (r *SplitNewParamsConfigurationSplittingStrategy) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
func init() {
apijson.RegisterFieldValidator[SplitNewParamsConfigurationSplittingStrategy](
"allow_uncategorized", "forbid", "include", "omit",
)
}
// Configuration for a single outbound webhook endpoint.
type SplitNewParamsWebhookConfiguration struct {
// Response format sent to the webhook: 'string' (default) or 'json'
WebhookOutputFormat param.Opt[string] `json:"webhook_output_format,omitzero"`
// Shared signing secret used to sign webhook deliveries. When set, each request
// includes an HMAC-SHA256 signature of the request body in the 'LC-Signature'
// header (value 'sha256=<hex>'). Recompute the HMAC over the raw request body with
// this secret to verify the delivery is authentic.
WebhookSigningSecret param.Opt[string] `json:"webhook_signing_secret,omitzero"`
// URL to receive webhook POST notifications
WebhookURL param.Opt[string] `json:"webhook_url,omitzero"`
// Events to subscribe to (e.g. 'parse.success', 'extract.error'). If null, all
// events are delivered.
//
// Any of "batch.cancelled", "batch.error", "batch.pending", "batch.running",
// "batch.success", "classify.cancelled", "classify.error",
// "classify.partial_success", "classify.pending", "classify.running",
// "classify.success", "extract.cancelled", "extract.error",
// "extract.partial_success", "extract.pending", "extract.success",
// "parse.cancelled", "parse.error", "parse.partial_success", "parse.pending",
// "parse.running", "parse.success", "sheets.cancelled", "sheets.error",
// "sheets.partial_success", "sheets.pending", "sheets.success", "split.cancelled",
// "split.error", "split.pending", "split.processing", "split.success",
// "unmapped_event", "verify.cancelled", "verify.error", "verify.pending",
// "verify.running", "verify.success".
WebhookEvents []string `json:"webhook_events,omitzero"`
// Custom HTTP headers sent with each webhook request (e.g. auth tokens)
WebhookHeaders map[string]string `json:"webhook_headers,omitzero"`
paramObj
}
func (r SplitNewParamsWebhookConfiguration) MarshalJSON() (data []byte, err error) {
type shadow SplitNewParamsWebhookConfiguration
return param.MarshalObject(r, (*shadow)(&r))
}
func (r *SplitNewParamsWebhookConfiguration) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type SplitListParams struct {
// Include items created at or after this timestamp (inclusive)
CreatedAtOnOrAfter param.Opt[time.Time] `query:"created_at_on_or_after,omitzero" format:"date-time" json:"-"`
// Include items created at or before this timestamp (inclusive)
CreatedAtOnOrBefore param.Opt[time.Time] `query:"created_at_on_or_before,omitzero" format:"date-time" json:"-"`
OrganizationID param.Opt[string] `query:"organization_id,omitzero" format:"uuid" json:"-"`
PageSize param.Opt[int64] `query:"page_size,omitzero" json:"-"`
PageToken param.Opt[string] `query:"page_token,omitzero" json:"-"`
ProjectID param.Opt[string] `query:"project_id,omitzero" format:"uuid" json:"-"`
// Filter by specific job IDs
JobIDs []string `query:"job_ids,omitzero" json:"-"`
// Filter by job status (pending, processing, completed, failed, cancelled)
//
// Any of "cancelled", "completed", "failed", "pending", "processing".
Status SplitListParamsStatus `query:"status,omitzero" json:"-"`
paramObj
}
// URLQuery serializes [SplitListParams]'s query parameters as `url.Values`.
func (r SplitListParams) URLQuery() (v url.Values, err error) {
return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
ArrayFormat: apiquery.ArrayQueryFormatRepeat,
NestedFormat: apiquery.NestedQueryFormatBrackets,
})
}
// Filter by job status (pending, processing, completed, failed, cancelled)
type SplitListParamsStatus string
const (
SplitListParamsStatusCancelled SplitListParamsStatus = "cancelled"
SplitListParamsStatusCompleted SplitListParamsStatus = "completed"
SplitListParamsStatusFailed SplitListParamsStatus = "failed"
SplitListParamsStatusPending SplitListParamsStatus = "pending"
SplitListParamsStatusProcessing SplitListParamsStatus = "processing"
)
type SplitDeleteParams struct {
OrganizationID param.Opt[string] `query:"organization_id,omitzero" format:"uuid" json:"-"`
ProjectID param.Opt[string] `query:"project_id,omitzero" format:"uuid" json:"-"`
paramObj
}
// URLQuery serializes [SplitDeleteParams]'s query parameters as `url.Values`.
func (r SplitDeleteParams) URLQuery() (v url.Values, err error) {
return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
ArrayFormat: apiquery.ArrayQueryFormatRepeat,
NestedFormat: apiquery.NestedQueryFormatBrackets,
})
}
type SplitCancelParams struct {
OrganizationID param.Opt[string] `query:"organization_id,omitzero" format:"uuid" json:"-"`
ProjectID param.Opt[string] `query:"project_id,omitzero" format:"uuid" json:"-"`
paramObj
}
// URLQuery serializes [SplitCancelParams]'s query parameters as `url.Values`.
func (r SplitCancelParams) URLQuery() (v url.Values, err error) {
return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
ArrayFormat: apiquery.ArrayQueryFormatRepeat,
NestedFormat: apiquery.NestedQueryFormatBrackets,
})
}
type SplitGetParams struct {
OrganizationID param.Opt[string] `query:"organization_id,omitzero" format:"uuid" json:"-"`
ProjectID param.Opt[string] `query:"project_id,omitzero" format:"uuid" json:"-"`
paramObj
}
// URLQuery serializes [SplitGetParams]'s query parameters as `url.Values`.
func (r SplitGetParams) URLQuery() (v url.Values, err error) {
return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
ArrayFormat: apiquery.ArrayQueryFormatRepeat,
NestedFormat: apiquery.NestedQueryFormatBrackets,
})
}