# Batch Priority

You can mark some batch jobs as higher priority than others. Priority is specified as an integer passed via the `metadata` field when creating a batch.

## How It Works

* Batches have a **default priority of 0**.
* Set a higher number for higher priority. For example, a batch with priority `1` will be processed before a batch with priority `0`.
* Priority is passed as a metadata key-value pair: `"PARASAIL_PRIORITY": "1"`.

## Usage

Add the `PARASAIL_PRIORITY` key to the `metadata` field when creating a batch:

{% tabs %}
{% tab title="openai-batch" %}

```python
from openai_batch import Batch

with Batch() as batch:
    for i in range(100):
        batch.add_to_batch(
            model="NousResearch/DeepHermes-3-Mistral-24B-Preview",
            messages=[{"role": "user", "content": f"Prompt #{i}"}]
        )
    batch.submit(metadata={"PARASAIL_PRIORITY": "1"})
```

{% endtab %}

{% tab title="Python (OpenAI SDK)" %}

```python
from openai import OpenAI

client = OpenAI(
    base_url="https://api.saas.parasail.io/v1",
    api_key="$PARASAIL_API_KEY",
)

batch = client.batches.create(
    input_file_id="file-abc123",
    endpoint="/v1/chat/completions",
    completion_window="24h",
    metadata={
        "PARASAIL_PRIORITY": "1"
    }
)
```

{% endtab %}

{% tab title="curl" %}

```bash
curl https://api.saas.parasail.io/v1/batches \
  -H "Authorization: Bearer $PARASAIL_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "input_file_id": "file-abc123",
    "endpoint": "/v1/chat/completions",
    "completion_window": "24h",
    "metadata": {
      "PARASAIL_PRIORITY": "1"
    }
  }'
```

{% endtab %}
{% endtabs %}

## Notes

* The `metadata` field follows the same format as the [OpenAI Batch API](https://platform.openai.com/docs/api-reference/batch/create#batch_create-metadata). Up to 16 key-value pairs can be attached to a batch.
* Priority values are integers. Higher numbers mean higher priority.
* Batches without `PARASAIL_PRIORITY` set default to `0`.
