Class: Copyleaks::CopyleaksAiImageDetectionRequestModel

Inherits:
Object
  • Object
show all
Defined in:
lib/copyleaks/models/imageDetection/requests/CopyleaksAiImageDetectionRequestModel.rb

Overview

Request model for Copyleaks AI image detection. The request body is a JSON object containing the image to analyze.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base64, file_name, model, sandbox = false) ⇒ CopyleaksAiImageDetectionRequestModel

Initialize a new CopyleaksAiImageDetectionRequestModel



16
17
18
19
20
21
# File 'lib/copyleaks/models/imageDetection/requests/CopyleaksAiImageDetectionRequestModel.rb', line 16

def initialize(base64, file_name, model, sandbox = false)
  @base64 = base64
  @file_name = file_name
  @model = model
  @sandbox = sandbox
end

Instance Attribute Details

#base64 ⇒ String

The base64-encoded image data to be analyzed for AI generation.

Requirements:

  • Minimum 512×512px, maximum 16 megapixels, less than 32MB
  • Supported formats: PNG, JPEG, BMP, WebP, HEIC/HEIF

Examples:

"aGVsbG8gd29ybGQ="



31
32
33
# File 'lib/copyleaks/models/imageDetection/requests/CopyleaksAiImageDetectionRequestModel.rb', line 31

def base64
  @base64
end

#file_name ⇒ String

The name of the image file including its extension.

Requirements:

  • Supported extensions: .png, .bmp, .jpg, .jpeg, .webp, .heic, .heif
  • Maximum 255 characters

Examples:

"my-image.png"



41
42
43
# File 'lib/copyleaks/models/imageDetection/requests/CopyleaksAiImageDetectionRequestModel.rb', line 41

def file_name
  @file_name
end

#model ⇒ String

The AI detection model to use for analysis. You can use either the full model name or its alias.

Available models:

  • AI Image 1 Ultra: "ai-image-1-ultra-01-09-2025" (full name) or "ai-image-1-ultra" (alias) AI image detection model. Produces an overlay of the detected AI segments.

Examples:

"ai-image-1-ultra-01-09-2025" or "ai-image-1-ultra"



52
53
54
# File 'lib/copyleaks/models/imageDetection/requests/CopyleaksAiImageDetectionRequestModel.rb', line 52

def model
  @model
end

#sandbox ⇒ Boolean

Use sandbox mode to test your integration with the Copyleaks API without consuming any credits.

Submit images for AI detection and get returned mock results, simulating Copyleaks' API functionality to ensure you have successfully integrated the API. This feature is intended to be used for development purposes only. Default value is false.

Examples:

false



63
64
65
# File 'lib/copyleaks/models/imageDetection/requests/CopyleaksAiImageDetectionRequestModel.rb', line 63

def sandbox
  @sandbox
end

Instance Method Details

#to_hash ⇒ Hash

Convert the model to a hash for JSON serialization



68
69
70
71
72
73
74
75
# File 'lib/copyleaks/models/imageDetection/requests/CopyleaksAiImageDetectionRequestModel.rb', line 68

def to_hash
  {
    base64: @base64,
    fileName: @file_name,
    model: @model,
    sandbox: @sandbox
  }
end

#to_json(*args) ⇒ String

Convert the model to JSON



80
81
82
# File 'lib/copyleaks/models/imageDetection/requests/CopyleaksAiImageDetectionRequestModel.rb', line 80

def to_json(*args)
  to_hash.to_json(*args)
end

#validate! ⇒ Object

Validate the model data

Raises:

  • (ArgumentError) —

    If required fields are missing or invalid



87
88
89
90
91
92
93
94
# File 'lib/copyleaks/models/imageDetection/requests/CopyleaksAiImageDetectionRequestModel.rb', line 87

def validate!
  raise ArgumentError, 'base64 is required' if @base64.nil? || @base64.empty?
  raise ArgumentError, 'file_name is required' if @file_name.nil? || @file_name.empty?
  raise ArgumentError, 'model is required' if @model.nil? || @model.empty?
  
  validate_file_name!
  validate_file_size!
end