Class: ReductoAI::Resources::Edit

Inherits:
Object
  • Object
show all
Defined in:
lib/reducto_ai/resources/edit.rb

Overview

Note:

Edit operations consume credits based on document size and instruction complexity.

Edit resource for PDF markup and annotation operations.

Generates marked-up PDFs with highlights, annotations, or redactions based on natural language instructions.

Examples:

Highlight key terms

client = ReductoAI::Client.new
result = client.edit.sync(
  input: "https://example.com/contract.pdf",
  instructions: "Highlight all mentions of payment terms and deadlines"
)
marked_pdf_url = result["result"]["document_url"]

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Edit

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Edit.

Parameters:

  • client (Client)

    the Reducto API client



23
24
25
# File 'lib/reducto_ai/resources/edit.rb', line 23

def initialize(client)
  @client = client
end

Instance Method Details

#async(input:, instructions:, async: nil, **options) ⇒ Hash

Generates a marked-up PDF asynchronously.

Returns immediately with a job_id. Poll with Jobs#retrieve to get results.

Examples:

job = client.edit.async(
  input: "https://example.com/legal-doc.pdf",
  instructions: "Highlight all liability clauses"
)
job_id = job["job_id"]

Parameters:

  • input (String, Hash)

    Document URL or hash with :url key

  • instructions (String)

    Natural language editing instructions

  • async (Boolean, nil) (defaults to: nil)

    Async mode flag

  • options (Hash)

    Additional editing options

Returns:

  • (Hash)

    Job status with keys:

    • "job_id" [String] - Job identifier for polling
    • "status" [String] - Initial status ("processing")

Raises:

  • (ArgumentError)

    if input or instructions are nil/empty

See Also:



85
86
87
88
89
90
91
92
93
94
95
# File 'lib/reducto_ai/resources/edit.rb', line 85

def async(input:, instructions:, async: nil, **options)
  raise ArgumentError, "input is required" if input.nil?
  if instructions.nil? || (instructions.respond_to?(:empty?) && instructions.empty?)
    raise ArgumentError, "instructions are required"
  end

  payload = build_payload(input, instructions, options)
  payload[:async] = async unless async.nil?

  @client.post("/edit_async", payload)
end

#sync(input:, instructions:, **options) ⇒ Hash

Generates a marked-up PDF synchronously.

Examples:

Redact sensitive info

result = client.edit.sync(
  input: "https://example.com/report.pdf",
  instructions: "Redact all social security numbers"
)

Parameters:

  • input (String, Hash)

    Document URL or hash with :url key

  • instructions (String)

    Natural language editing instructions (e.g., "Highlight all dates", "Redact personal information")

  • options (Hash)

    Additional editing options

Returns:

  • (Hash)

    Edit results with keys:

    • "job_id" [String] - Job identifier
    • "status" [String] - Job status ("succeeded")
    • "result" [Hash] - Contains "document_url" with marked PDF
    • "usage" [Hash] - Credit usage details

Raises:

  • (ArgumentError)

    if input or instructions are nil/empty

  • (ClientError)

    if instructions are invalid

  • (ServerError)

    if editing fails

See Also:



51
52
53
54
55
56
57
58
59
# File 'lib/reducto_ai/resources/edit.rb', line 51

def sync(input:, instructions:, **options)
  raise ArgumentError, "input is required" if input.nil?
  if instructions.nil? || (instructions.respond_to?(:empty?) && instructions.empty?)
    raise ArgumentError, "instructions are required"
  end

  payload = build_payload(input, instructions, options)
  @client.post("/edit", payload)
end