Skip to main content

Asynchronous dataset imports

On this page you import a file of examples into a dataset: question and answer pairs from CSV for a text project, or training pairs from CSV or JSONL for an embedding project. For an OpenAI chat fine-tuning file (JSONL), see Coming from OpenAI?: those conversations go through the chats API instead.

Every import follows the same steps: create the import, upload the file, check how its columns map, and confirm. Confirming queues the import and returns at once; the rows are added in the background, and you poll until it finishes.

Import a CSV into a text project​

A text project's dataset accepts a UTF-8 CSV with a header row. Each row is one question and its answer, which become a user turn and an assistant turn. For example, support.csv:

prompt,response,tags
Can I return this?,"Yes, within 30 days.",support
Who pays for return shipping?,We do.,"support,shipping"

The sequence below runs the whole import with cURL and jq. Replace acme/support with your owner and project slugs.

BASE="https://reopenly.com/api/v1/projects/acme/support"
AUTH="Authorization: Bearer $REOPENLY_API_KEY"

# 1. Find the dataset. A text project lists its one chat dataset here.
DATASET_ID=$(curl -s "$BASE/datasets" -H "$AUTH" | jq -r '.data[0].id')

# 2. Create the import.
IMPORT_ID=$(curl -s -X POST "$BASE/datasets/$DATASET_ID/imports" \
-H "$AUTH" -H "Content-Type: application/json" \
--data '{"filename": "support.csv"}' | jq -r '.import.id')

# 3. Upload the file bytes.
curl -s -X PUT "$BASE/imports/$IMPORT_ID/content" \
-H "$AUTH" -H "Content-Type: text/csv" \
--data-binary @support.csv

# 4. Profile it: headers, samples, size, SHA-256 and a suggested mapping.
PROFILE=$(curl -s -X POST "$BASE/imports/$IMPORT_ID/profile" -H "$AUTH")
echo "$PROFILE" | jq '.profile | {headers, mapping, warnings}'
SHA256=$(echo "$PROFILE" | jq -r '.profile.sha256')

# 5. Preview a sample of the rows under your mapping.
curl -s -X POST "$BASE/imports/$IMPORT_ID/preview" \
-H "$AUTH" -H "Content-Type: application/json" \
--data '{"mapping": {"question": "prompt", "answer": "response", "tags": "tags"},
"invalid_row_policy": "skip"}' | jq '.preview.counts'

# 6. Confirm with the same mapping, the profiled digest and a key of your own.
curl -s -X POST "$BASE/imports/$IMPORT_ID/confirm" \
-H "$AUTH" -H "Content-Type: application/json" \
--data "{\"mapping\": {\"question\": \"prompt\", \"answer\": \"response\", \"tags\": \"tags\"},
\"invalid_row_policy\": \"skip\",
\"expected_sha256\": \"$SHA256\",
\"idempotency_key\": \"support-csv-$IMPORT_ID\"}"

# 7. Poll until the import finishes.
while true; do
STATE=$(curl -s "$BASE/imports/$IMPORT_ID" -H "$AUTH" | jq -r '.import.state')
echo "$STATE"
case "$STATE" in succeeded|failed|cancelled) break ;; esac
sleep 5
done
curl -s "$BASE/imports/$IMPORT_ID" -H "$AUTH" \
| jq '.import | {rows_read, rows_valid, rows_skipped, chats_created, messages_created, error_code, error_sample}'

What each step checks:

  • Create accepts an optional filename and an optional size_bytes; a declared size over the upload limit is refused with 413 import_too_large before you upload. The response's upload object says where to send the bytes (method, url and headers).
  • Profile reads the file once and returns headers, sample_rows, row_estimate, byte_size, sha256, a suggested mapping and warnings (for example two columns that could fill the same field). Check the suggestion before you confirm.
  • Preview transforms only the sampled rows. Its counts describe the sample, not the whole file.
  • Confirm binds the import to the profiled file through expected_sha256: if the file changed since, it answers 409 import_object_changed. It reserves the dataset capacity the rows need and queues the import. Sending the same idempotency_key again returns the import already queued instead of starting a second one.

Mapping and options​

mapping names, for each field, the CSV column that fills it:

{"question": "prompt", "answer": "response", "chat_id": "conversation", "tags": "tags"}

question and answer are required; chat_id and tags are optional. Profile suggests a mapping from common header names (question, prompt, answer, response, completion and so on). One column can fill only one field.

  • Without chat_id, every row is its own chat. With it, rows that share a chat_id become one multi-turn chat, in file order.
  • tags is a comma-separated list, kept up to 32 tags per chat. Tags are how a training run selects its data.
  • A row with only a question or only an answer, or a field longer than 20,480 characters, is invalid: invalid_row_policy: "fail" (the default) refuses the file, "skip" drops those rows and counts them. Wholly blank rows are ignored.

Two more options sit next to mapping in the preview and confirm body, not inside it. Both are off by default and are meant for classification data, where the answer is a label:

{
"mapping": {"question": "text", "answer": "label"},
"invalid_row_policy": "fail",
"tags_from_answer": true,
"category_from_answer": true
}

tags_from_answer: true also adds each answer as a tag, and category_from_answer: true records the answer as the chat's category. A chat whose rows disagree about the label gets no category. Embedding imports refuse both options with 422 import_options_kind_mismatch.

Preview and confirm refuse a mapping they cannot accept with 422 and a typed code such as mapping_required_column, mapping_unknown_column or mapping_duplicate_column.

Import training pairs into an embedding project​

An embedding dataset accepts UTF-8 CSV or JSONL (.jsonl/.ndjson, one flat object per line). The steps are the same as above, with the embedding dataset's ID and an explicit mapping:

{"anchor": "query", "positive": "passage", "negative": "hard_negative", "metadata": ["language"]}

anchor and positive are required. negative and metadata are optional. Mapped JSONL values must be strings. A duplicate JSON key is refused; a nested or non-string mapped value is an invalid row. Each valid row creates a new pair, reuses an existing pair with the same negative, or is reported as a conflict when the negative differs. Reuse keeps the existing example and records another source-row link. The shared 512 MiB text budget counts stored example text and metadata. Confirm reserves the exact bytes of the valid mapped rows; when the import finishes, the reservation is settled against the rows actually created. A finished embedding import reports embedding_examples_created, embedding_examples_reused and embedding_examples_conflicted.

Reference​

GET /api/v1/projects/{owner_slug}/{project_slug}/datasets/limits
GET /api/v1/projects/{owner_slug}/{project_slug}/datasets/{dataset_id}/limits
POST /api/v1/projects/{owner_slug}/{project_slug}/datasets/{dataset_id}/imports
PUT /api/v1/projects/{owner_slug}/{project_slug}/imports/{import_id}/content
POST /api/v1/projects/{owner_slug}/{project_slug}/imports/{import_id}/profile
POST /api/v1/projects/{owner_slug}/{project_slug}/imports/{import_id}/preview
POST /api/v1/projects/{owner_slug}/{project_slug}/imports/{import_id}/confirm
GET /api/v1/projects/{owner_slug}/{project_slug}/imports
GET /api/v1/projects/{owner_slug}/{project_slug}/imports/{import_id}
POST /api/v1/projects/{owner_slug}/{project_slug}/imports/{import_id}/cancel

Limits. /datasets/{dataset_id}/limits publishes the upload and dataset bounds plus that dataset's used and remaining capacity; /datasets/limits answers the same for the project's default dataset. Chat datasets report examples, messages and text bytes. Embedding datasets report examples and text bytes. An unknown dataset ID, or one from another project, answers 404 and never falls back to the default dataset.

States. An import moves through created, uploaded, profiling, ready_for_mapping and importing, and ends succeeded, failed or cancelled. purging means the rows of a failed or cancelled import are being removed in batches. Rows of an unfinished import are not visible in the dataset and are not used for training. Cancelling releases the reserved capacity.

Errors use {"detail": {"code", "message"}}. Capacity failures have typed 409 codes; a changed upload returns 409 import_object_changed. A finished import reports its counts and a bounded sample of error reasons in error_sample.

Listing. The imports list returns {data, next_cursor, total_count}, newest first. Use limit (default 25, maximum 50) and pass next_cursor as cursor for the next page. Optional dataset_id filters both the rows and the total. Keep the same dataset filter when following a cursor.