Gemini.Types.BatchJob (GeminiEx v0.8.2)

View Source

Type definitions for batch processing jobs.

Batch processing allows submitting large numbers of requests at once with 50% cost savings compared to interactive API calls.

Batch Job States

  • :job_state_unspecified - Initial/unknown state
  • :queued - Job is queued for processing
  • :pending - Job is preparing to run
  • :running - Job is actively processing
  • :succeeded - Job completed successfully
  • :failed - Job failed
  • :cancelling - Job is being cancelled
  • :cancelled - Job was cancelled
  • :paused - Job is paused (Vertex AI)
  • :expired - Job expired
  • :partially_succeeded - Some requests succeeded, some failed

Example

# Create a batch job
{:ok, batch} = Gemini.APIs.Batches.create(
  "gemini-2.0-flash",
  file_name: "files/input-12345"
)

# Poll for completion
{:ok, completed} = Gemini.APIs.Batches.wait(batch.name)

# Get results
if BatchJob.succeeded?(completed) do
  IO.puts("Processed #{completed.completion_stats.total_count} requests")
end

Summary

Types

Batch job destination configuration.

Batch job source configuration.

Completion statistics for a batch job.

Batch job error details.

Batch job state enumeration.

t()

Represents a batch processing job.

Functions

Checks if the batch job was cancelled.

Checks if the batch job is complete (terminal state).

Checks if the batch job failed.

Creates a BatchJob from API response.

Extracts the batch ID from the full name.

Gets the completion percentage if available.

Parses API state string to atom.

Checks if the batch job is still running.

Converts job state atom to API string format.

Checks if the batch job succeeded.

Types

batch_destination()

@type batch_destination() :: %{
  optional(:file_name) => String.t(),
  optional(:gcs_uri) => String.t(),
  optional(:bigquery_uri) => String.t(),
  optional(:format) => String.t(),
  optional(:inlined_responses) => [map()]
}

Batch job destination configuration.

batch_source()

@type batch_source() :: %{
  optional(:file_name) => String.t(),
  optional(:gcs_uri) => [String.t()],
  optional(:bigquery_uri) => String.t(),
  optional(:format) => String.t(),
  optional(:inlined_requests) => [map()]
}

Batch job source configuration.

completion_stats()

@type completion_stats() :: %{
  optional(:total_count) => integer(),
  optional(:success_count) => integer(),
  optional(:failure_count) => integer()
}

Completion statistics for a batch job.

job_error()

@type job_error() :: %{
  optional(:code) => integer(),
  optional(:message) => String.t(),
  optional(:details) => [String.t()]
}

Batch job error details.

job_state()

@type job_state() ::
  :job_state_unspecified
  | :queued
  | :pending
  | :running
  | :succeeded
  | :failed
  | :cancelling
  | :cancelled
  | :paused
  | :expired
  | :partially_succeeded

Batch job state enumeration.

t()

@type t() :: %Gemini.Types.BatchJob{
  completion_stats: completion_stats() | nil,
  create_time: String.t() | nil,
  dest: batch_destination() | nil,
  display_name: String.t() | nil,
  end_time: String.t() | nil,
  error: job_error() | nil,
  model: String.t() | nil,
  name: String.t() | nil,
  src: batch_source() | nil,
  start_time: String.t() | nil,
  state: job_state() | nil,
  update_time: String.t() | nil
}

Represents a batch processing job.

Fields

  • name - Resource name (e.g., "batches/abc123" for Gemini, "batchPredictionJobs/123" for Vertex)
  • display_name - Human-readable name
  • state - Current job state
  • model - Model used for processing
  • src - Input source configuration
  • dest - Output destination configuration
  • create_time - When the job was created
  • start_time - When the job started running
  • end_time - When the job completed
  • update_time - Last update timestamp
  • error - Error details if failed
  • completion_stats - Processing statistics

Functions

cancelled?(arg1)

@spec cancelled?(t()) :: boolean()

Checks if the batch job was cancelled.

complete?(arg1)

@spec complete?(t()) :: boolean()

Checks if the batch job is complete (terminal state).

failed?(arg1)

@spec failed?(t()) :: boolean()

Checks if the batch job failed.

from_api_response(response)

@spec from_api_response(map()) :: t()

Creates a BatchJob from API response.

Handles both Gemini API and Vertex AI response formats.

get_id(batch_job)

@spec get_id(t()) :: String.t() | nil

Extracts the batch ID from the full name.

get_progress(batch_job)

@spec get_progress(t()) :: float() | nil

Gets the completion percentage if available.

parse_state(arg1)

@spec parse_state(String.t() | nil) :: job_state() | nil

Parses API state string to atom.

running?(arg1)

@spec running?(t()) :: boolean()

Checks if the batch job is still running.

state_to_api(atom)

@spec state_to_api(job_state()) :: String.t()

Converts job state atom to API string format.

succeeded?(arg1)

@spec succeeded?(t()) :: boolean()

Checks if the batch job succeeded.