# Create Finetune Job

`POST /v1/finetune`

Start a new finetune job via the pipeline API.

- Base URL: `https://api.qualia.dev`
- Authentication: an API key in the `X-API-Key` header, or `Authorization: Bearer …`

## Request body

Required: `application/json` `FinetuneRequest`

## Responses

- `200` Finetune job created successfully: `application/json` `FinetuneResponse`
- `400` Invalid camera mappings or request parameters: `application/json` `ErrorResponse`
- `401` Invalid or missing API key: `application/json` `ErrorResponse`
- `403` Training isn't available on your account's plan: `application/json` `ErrorResponse`
- `422` Validation error

## Schemas

```yaml
FinetuneRequest:
  properties:
    project_id:
      type: string
      format: uuid
      description: Project ID to associate the job with
    model_id:
      description: HuggingFace model ID to finetune. Required for pi05. Must NOT be provided for act.
      examples:
        - lerobot/pi05_base
        - myuser/my-finetuned-pi05
      type:
        - string
        - "null"
    model_revision:
      description: Exact Hugging Face commit SHA. The server supplies the reviewed pin for a built-in foundation-model alias; custom model IDs must always provide this value.
      pattern: ^[0-9a-f]{40}$
      type:
        - string
        - "null"
    vla_type:
      $ref: "#/components/schemas/VLAType"
      description: VLA model type (determines camera slot configuration). smolvla and sarm were retired on 2026-10-14 and are refused.
      examples:
        - act
        - pi05
    dataset_version_id:
      type: string
      format: uuid
      description: Immutable QDS DatasetVersion ID. Training never accepts mutable repository names, branches, or external dataset identifiers.
    hours:
      type: number
      maximum: 168
      exclusiveMinimum: 0
      description: Training duration in hours
    instance_type:
      description: GPU instance type (from /v1/instances). If not specified, cheapest available is used.
      type:
        - string
        - "null"
    region:
      description: Cloud region. If not specified, best available is selected.
      type:
        - string
        - "null"
    batch_size:
      type: integer
      maximum: 512
      minimum: 1
      description: Training batch size
      default: 32
    name:
      description: Job name/description. Defaults to 'SDK Job - {vla_type}'
      maxLength: 255
      type:
        - string
        - "null"
    model_name:
      description: Output model name, independent of the job description.
      maxLength: 193
      type:
        - string
        - "null"
    camera_mappings:
      additionalProperties:
        type: string
      type: object
      description: Camera mappings from model camera slots to dataset image keys.
      example:
        cam_1: observation.images.top
        cam_2: observation.images.wrist
        cam_3: observation.images.front
    vla_hyper_spec:
      description: Advanced hyperparameters for VLA models. Use GET /v1/finetune/hyperparams/defaults to get defaults.
      nullable: true
      additionalProperties: true
      type: object
    job_type:
      $ref: "#/components/schemas/JobType"
      description: Type of fine-tuning job. Only 'vla'; 'reward' and 'vla_w_reward' were retired on 2026-10-14 and are refused.
      default: vla
    compute_overrides:
      description: Optional per-run compute dispatch overrides. Supports ``dev_session`` (pin to a named dev VM) and ``driver`` (pick a non-default backend like ``"gcp"``) — see ``ComputeOverrides``. ``dev_session`` and any ``booking`` hint are refused with 400 outside internal environments.
      nullable: true
      allOf:
        - $ref: "#/components/schemas/ComputeOverrides"
  additionalProperties: false
  type: object
  required:
    - project_id
    - vla_type
    - dataset_version_id
    - hours
    - camera_mappings
  title: FinetuneRequest
  description: Request to start a finetune job.
VLAType:
  type: string
  enum:
    - act
    - pi05
  title: VLAType
  description: VLA model types a new finetune can use.
JobType:
  type: string
  enum:
    - vla
  title: JobType
  description: Fine-tuning job types a new finetune can use.
ComputeOverrides:
  properties:
    dev_session:
      description: "Name of an existing dev session VM (as registered via `qcore session start <name>`). When set, all ops in this pipeline run are dispatched to that VM via the Verda Instances driver, bypassing the prod Verda Containers path. The session must exist and be in status=running. Internal environments only: refused with 400 elsewhere."
      type:
        - string
        - "null"
    driver:
      description: Name of a non-default compute backend to route every container op of this run to. Today only ``"gcp"`` is recognized — it pins dispatch to the ``GcpContainerDriver`` (Google Cloud Batch). Requires the pipeline-api deployment to have GCP credentials configured; ignored otherwise.
      const: gcp
      type:
        - string
        - "null"
    hints:
      description: "Run-level dispatch hints — forwarded verbatim to pipeline-api's ``ComputeHints`` model. Supported keys: ``drivers`` (ordered list of preferences), ``max_wait_seconds`` (capacity-wait window; on CapacityExhausted the run enters SCHEDULED and the scheduler retries every 30s until the deadline), and ``booking`` (whole-run VM pinning; internal environments only, refused with 400 elsewhere). Pipeline-api validates the shape; bad inputs are 400'd at submit time."
      examples:
        - max_wait_seconds: 3600
      nullable: true
      additionalProperties: true
      type: object
    op_hints:
      description: "Per-op dispatch hints, keyed by op_type — forwarded verbatim to pipeline-api, where each op resolves its effective ``ComputeHints`` as: per-op override (this) > run-level ``hints`` > template default. Use this to pick compute for the training op (``finetune_<vla_type>``) without overriding the cheap defaults of control-plane ops like credit reservation. ``booking`` is refused with 400 outside internal environments."
      examples:
        - finetune_act:
            drivers:
              - driver: verda_container
                gpu: L40S
      nullable: true
      additionalProperties: true
      type: object
  type: object
  title: ComputeOverrides
  description: |-
    Per-run overrides for the pipeline's compute dispatch.

    Two escape hatches today:

    - ``dev_session`` — naming a running dev session VM routes every op in
     this pipeline run to a ``VerdaInstanceDriver`` targeting that VM
     instead of the standard ``VerdaContainerDriver``.
    - ``driver`` — naming a backend (``"gcp"``) routes every container op
     of this run to that backend's driver (e.g. ``GcpContainerDriver``,
     dispatching to Google Cloud Batch) instead of the registry default.

    Kept as its own model (rather than flat fields on the request) so
    future overrides (region, instance_type pinning, etc.) plug in here
    without growing the request surface. If both ``dev_session`` and
    ``driver`` are supplied, ``dev_session`` wins (the dev VM path is
    more specific — it pins to a concrete resolved VM).
FinetuneResponse:
  properties:
    job_id:
      type: string
      format: uuid
      description: Unique job identifier
    status:
      type: string
      description: Current job status
    message:
      description: Status message
      type:
        - string
        - "null"
  type: object
  required:
    - job_id
    - status
  title: FinetuneResponse
  description: Response after creating a finetune job.
ErrorResponse:
  properties:
    detail:
      type: string
      description: Error message describing what went wrong
  type: object
  required:
    - detail
  title: ErrorResponse
  description: Standard error response.
```
