# `Gemini.Types.BatchJob`
[🔗](https://github.com/nshkrdotcom/gemini_ex/blob/v0.11.0/lib/gemini/types/batch.ex#L1)

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

# `batch_destination`
[🔗](https://github.com/nshkrdotcom/gemini_ex/blob/v0.11.0/lib/gemini/types/batch.ex#L71)

```elixir
@type batch_destination() :: %{
  optional(:file_name) =&gt; String.t(),
  optional(:gcs_uri) =&gt; String.t(),
  optional(:bigquery_uri) =&gt; String.t(),
  optional(:format) =&gt; String.t(),
  optional(:inlined_responses) =&gt; [map()]
}
```

Batch job destination configuration.

# `batch_source`
[🔗](https://github.com/nshkrdotcom/gemini_ex/blob/v0.11.0/lib/gemini/types/batch.ex#L60)

```elixir
@type batch_source() :: %{
  optional(:file_name) =&gt; String.t(),
  optional(:gcs_uri) =&gt; [String.t()],
  optional(:bigquery_uri) =&gt; String.t(),
  optional(:format) =&gt; String.t(),
  optional(:inlined_requests) =&gt; [map()]
}
```

Batch job source configuration.

# `completion_stats`
[🔗](https://github.com/nshkrdotcom/gemini_ex/blob/v0.11.0/lib/gemini/types/batch.ex#L82)

```elixir
@type completion_stats() :: %{
  optional(:total_count) =&gt; integer(),
  optional(:success_count) =&gt; integer(),
  optional(:failure_count) =&gt; integer()
}
```

Completion statistics for a batch job.

# `job_error`
[🔗](https://github.com/nshkrdotcom/gemini_ex/blob/v0.11.0/lib/gemini/types/batch.ex#L91)

```elixir
@type job_error() :: %{
  optional(:code) =&gt; integer(),
  optional(:message) =&gt; String.t(),
  optional(:details) =&gt; [String.t()]
}
```

Batch job error details.

# `job_state`
[🔗](https://github.com/nshkrdotcom/gemini_ex/blob/v0.11.0/lib/gemini/types/batch.ex#L44)

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

Batch job state enumeration.

# `t`
[🔗](https://github.com/nshkrdotcom/gemini_ex/blob/v0.11.0/lib/gemini/types/batch.ex#L98)

```elixir
@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

# `cancelled?`
[🔗](https://github.com/nshkrdotcom/gemini_ex/blob/v0.11.0/lib/gemini/types/batch.ex#L228)

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

Checks if the batch job was cancelled.

# `complete?`
[🔗](https://github.com/nshkrdotcom/gemini_ex/blob/v0.11.0/lib/gemini/types/batch.ex#L200)

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

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

# `failed?`
[🔗](https://github.com/nshkrdotcom/gemini_ex/blob/v0.11.0/lib/gemini/types/batch.ex#L214)

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

Checks if the batch job failed.

# `from_api_response`
[🔗](https://github.com/nshkrdotcom/gemini_ex/blob/v0.11.0/lib/gemini/types/batch.ex#L141)

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

Creates a BatchJob from API response.

Handles both Gemini API and Vertex AI response formats.

# `get_id`
[🔗](https://github.com/nshkrdotcom/gemini_ex/blob/v0.11.0/lib/gemini/types/batch.ex#L253)

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

Extracts the batch ID from the full name.

# `get_progress`
[🔗](https://github.com/nshkrdotcom/gemini_ex/blob/v0.11.0/lib/gemini/types/batch.ex#L235)

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

Gets the completion percentage if available.

# `parse_state`
[🔗](https://github.com/nshkrdotcom/gemini_ex/blob/v0.11.0/lib/gemini/types/batch.ex#L178)

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

Parses API state string to atom.

# `running?`
[🔗](https://github.com/nshkrdotcom/gemini_ex/blob/v0.11.0/lib/gemini/types/batch.ex#L221)

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

Checks if the batch job is still running.

# `state_to_api`
[🔗](https://github.com/nshkrdotcom/gemini_ex/blob/v0.11.0/lib/gemini/types/batch.ex#L162)

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

Converts job state atom to API string format.

# `succeeded?`
[🔗](https://github.com/nshkrdotcom/gemini_ex/blob/v0.11.0/lib/gemini/types/batch.ex#L207)

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

Checks if the batch job succeeded.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
