# 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`.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.parasail.io/parasail-docs/batch/batch-priority.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
