> ## Documentation Index
> Fetch the complete documentation index at: https://docs.morphllm.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Create Fine-tuning Job

> Train a custom Reflex at /v1/fine_tuning/jobs

## Overview

Creates a fine-tuning job that trains a custom Reflex from labeled examples. The resulting `fine_tuned_model` id is usable in [`POST /v1/reflex/predict`](/api-reference/endpoint/reflex) when the job succeeds. Track progress with [job events](/api-reference/endpoint/fine-tuning-events).


## OpenAPI

````yaml POST /v1/fine_tuning/jobs
openapi: 3.1.0
info:
  title: Morph API
  version: 1.1.0
  description: >-
    The Morph public API at api.morphllm.com: OpenAI- and Anthropic-compatible
    inference (chat completions, messages), Fast Apply code editing, Compact
    context compression, Reflex classification, and fine-tuning. Model ids,
    prices, and context windows are served live at
    https://www.morphllm.com/api/models/json.
  contact:
    name: Morph
    url: https://morphllm.com
    email: info@morphllm.com
  license:
    name: Proprietary
    url: https://morphllm.com/privacy/tos
servers:
  - url: https://api.morphllm.com
    description: Production
security: []
tags:
  - name: chat
    description: >-
      OpenAI- and Anthropic-compatible chat inference, including Fast Apply and
      WarpGrep models.
  - name: compact
    description: Context compression for long agent conversations.
  - name: reflex
    description: 'Per-turn classifiers: realtime prediction and batches.'
  - name: fine-tuning
    description: Reflex fine-tuning job lifecycle.
  - name: models
    description: Model listing and management.
  - name: telemetry
    description: Usage reporting hooks.
paths:
  /v1/fine_tuning/jobs:
    post:
      tags:
        - fine-tuning
      summary: Train a Reflex
      description: >-
        Start a training job. OpenAI fine-tuning-compatible, with two
        differences: training data is **inline** (`training_data`, no Files API)
        and there are **no hyperparameters**. `model` selects the base to train
        from — omit it for a from-scratch cold start, or pass any custom or
        default reflex to warm-start from its weights. A small Reflex trains in
        about 30 seconds. Provide exactly one input mode — `training_data`,
        `generate`, or `label_data`.
      operationId: createFineTuningJob
      requestBody:
        required: true
        description: >-
          The training set (or the instructions to build one) plus the name to
          serve it under.
        content:
          application/json:
            example:
              suffix: support-classifier
              training_data:
                - text: I need a refund for my order
                  label: billing
                - text: Charged me twice this month
                  label: billing
                - text: The app crashed on launch
                  label: bug
                - text: Submit button does nothing
                  label: bug
            schema:
              $ref: '#/components/schemas/CreateFineTuningJobRequest'
      responses:
        '200':
          description: The created job.
          content:
            application/json:
              example:
                id: ftjob-a1b2c3d4-5e6f-7a8b-9c0d-1e2f3a4b5c6d
                object: fine_tuning.job
                model: guardrail
                created_at: 1780107000
                finished_at: 1780107148
                fine_tuned_model: support-classifier
                status: succeeded
                labels:
                  - billing
                  - bug
                trained_examples: 10
                hyperparameters:
                  n_epochs: 3
                  batch_size: auto
                  learning_rate_multiplier: auto
                result:
                  accuracy: 0.95
                  f1_score: 0.94
                error: null
                suffix: support-classifier
              schema:
                $ref: '#/components/schemas/FineTuningJob'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '429':
          $ref: '#/components/responses/RateLimited'
        '500':
          $ref: '#/components/responses/InternalError'
      security:
        - bearerAuth: []
components:
  schemas:
    CreateFineTuningJobRequest:
      type: object
      properties:
        model:
          type: string
          description: >-
            What to train from (OpenAI-style). Omit for a from-scratch cold
            start, or pass a custom or default reflex to warm-start from its
            weights: a model you trained (its `suffix` or job id) or a built-in
            reflex name like `guardrail`.
          example: guardrail
        suffix:
          type: string
          description: Names the served model. Becomes `fine_tuned_model` on success.
          example: support-classifier
        labels:
          type: array
          items:
            type: string
            description: One class name.
            example: billing
          description: >-
            The classes. 2+ required for `generate` and `label_data`; inferred
            from `training_data` if omitted.
          example:
            - billing
            - bug
        webhook_url:
          type: string
          description: >-
            An `https` URL that receives a signed webhook when the job reaches
            `succeeded`, `failed`, or `cancelled`.
          example: https://example.com/webhooks/morph
        auto_train:
          type: boolean
          default: true
          description: >-
            Train as soon as data prep finishes. Set `false` to pause at
            `prepared` for review, then call `POST
            /v1/fine_tuning/jobs/{job_id}/train`.
          example: true
        training_data:
          type: array
          items:
            type: object
            properties:
              text:
                type: string
                description: The raw text to classify.
                example: I need a refund for my order
              label:
                type: string
                description: The class this text belongs to.
                example: billing
            required:
              - text
              - label
            description: A single labeled training row.
            example:
              text: I need a refund for my order
              label: billing
          description: Labeled rows you supply (input mode 1).
          example:
            - text: I need a refund for my order
              label: billing
            - text: Charged me twice this month
              label: billing
            - text: The app crashed on launch
              label: bug
            - text: Submit button does nothing
              label: bug
        generate:
          type: object
          properties:
            description:
              type: string
              description: What the classifier is for.
              example: classify support tickets by topic
            examples_per_label:
              type: integer
              default: 500
              description: Examples to synthesize per label. 5–1000.
              example: 25
          description: 'Input mode 2: synthesize training data from a description.'
          example:
            description: classify support tickets by topic
            examples_per_label: 25
        label_data:
          type: object
          properties:
            texts:
              type: array
              items:
                type: string
                description: One unlabeled string to sort into a class.
                example: Charged me twice this month
              description: >-
                Unlabeled strings, up to 20,000. Minimum is your label count ×
                5.
              example:
                - Charged me twice this month
                - Submit button does nothing
            description:
              type: string
              description: Context for more accurate labeling.
              example: support tickets
          description: 'Input mode 3: sort your unlabeled text into your classes.'
          example:
            texts:
              - Charged me twice this month
              - Submit button does nothing
            description: support tickets
      description: >-
        Provide exactly one input: `training_data`, `generate`, or `label_data`.
        The training set must end up with 2+ labels and 5+ examples per label.
      example:
        suffix: support-classifier
        training_data:
          - text: I need a refund for my order
            label: billing
          - text: Charged me twice this month
            label: billing
          - text: The app crashed on launch
            label: bug
          - text: Submit button does nothing
            label: bug
    FineTuningJob:
      type: object
      properties:
        id:
          type: string
          description: Job id, prefixed `ftjob-`.
          example: ftjob-a1b2c3d4-5e6f-7a8b-9c0d-1e2f3a4b5c6d
        object:
          type: string
          description: Always `fine_tuning.job`.
          example: fine_tuning.job
        model:
          type: string
          description: >-
            What the job trained from: the reflex you warm-started from, or the
            from-scratch base for a cold start.
          example: guardrail
        created_at:
          type: integer
          description: Unix timestamp (seconds) at creation.
          example: 1780107000
        finished_at:
          type:
            - integer
            - 'null'
          description: Unix timestamp at a terminal state, else null.
          example: 1780107148
        fine_tuned_model:
          type:
            - string
            - 'null'
          description: >-
            Served model name once `succeeded` (the `suffix`, or the job id if
            none).
          example: support-classifier
        status:
          type: string
          enum:
            - queued
            - validating_files
            - running
            - succeeded
            - failed
            - cancelled
          description: >-
            `validating_files` is the data-prep phase for
            `generate`/`label_data` jobs.
          example: succeeded
        labels:
          type: array
          items:
            type: string
            description: One class the model predicts.
            example: billing
          description: The classes this job trained on.
          example:
            - billing
            - bug
        trained_examples:
          type: integer
          description: Number of training examples.
          example: 10
        hyperparameters:
          type: object
          properties:
            n_epochs:
              type: integer
              description: Passes over the training set.
              example: 3
            batch_size:
              type: string
              description: Batch size, always `auto`.
              example: auto
            learning_rate_multiplier:
              type: string
              description: Learning-rate multiplier, always `auto`.
              example: auto
          required:
            - n_epochs
            - batch_size
            - learning_rate_multiplier
          description: Fully managed.
          example:
            n_epochs: 3
            batch_size: auto
            learning_rate_multiplier: auto
        result:
          type:
            - object
            - 'null'
          properties:
            accuracy:
              type:
                - number
                - 'null'
              description: Held-out accuracy of the trained model.
              example: 0.95
            f1_score:
              type:
                - number
                - 'null'
              description: Held-out macro F1 of the trained model.
              example: 0.94
          required:
            - accuracy
            - f1_score
          description: >-
            `{accuracy, f1_score}` when `succeeded`, else null. Each value may
            be null.
          example:
            accuracy: 0.95
            f1_score: 0.94
        error:
          type:
            - object
            - 'null'
          properties:
            code:
              type:
                - string
                - 'null'
              description: Machine-readable failure code.
              example: invalid_training_data
            message:
              type:
                - string
                - 'null'
              description: Human-readable reason the training job failed.
              example: Every label needs at least 5 examples.
            param:
              type:
                - string
                - 'null'
              description: The request field that caused the failure.
              example: training_data
          required:
            - code
            - message
            - param
          description: '`{code, message, param}` when `failed`, else null.'
          example:
            code: invalid_training_data
            message: Every label needs at least 5 examples.
            param: training_data
        suffix:
          type:
            - string
            - 'null'
          description: The suffix supplied at creation, else null.
          example: support-classifier
      required:
        - id
        - object
        - model
        - created_at
        - finished_at
        - fine_tuned_model
        - status
        - labels
        - trained_examples
        - hyperparameters
        - result
        - error
        - suffix
      description: >-
        An OpenAI-compatible `fine_tuning.job`, with additive Reflex fields
        (`labels`, `trained_examples`, `result`, `suffix`).
      example:
        id: ftjob-a1b2c3d4-5e6f-7a8b-9c0d-1e2f3a4b5c6d
        object: fine_tuning.job
        model: guardrail
        created_at: 1780107000
        finished_at: 1780107148
        fine_tuned_model: support-classifier
        status: succeeded
        labels:
          - billing
          - bug
        trained_examples: 10
        hyperparameters:
          n_epochs: 3
          batch_size: auto
          learning_rate_multiplier: auto
        result:
          accuracy: 0.95
          f1_score: 0.94
        error: null
        suffix: support-classifier
    Error:
      type: object
      properties:
        error:
          type: object
          properties:
            code:
              type: string
              example: invalid_request_error
              description: Machine-readable error code.
            message:
              type: string
              example: The request body is missing the `model` field.
              description: Human-readable explanation of the failure.
          required:
            - code
            - message
      required:
        - error
      description: Standard error envelope returned by every non-2xx response.
      example:
        error:
          code: invalid_request_error
          message: The request body is missing the `model` field.
  responses:
    BadRequest:
      description: Malformed request — missing or invalid fields.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              code: invalid_request_error
              message: The request body is missing the `model` field.
    Unauthorized:
      description: Missing or invalid API key.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              code: unauthorized
              message: Invalid API key provided.
    RateLimited:
      description: Rate limited — retry after the interval in the Retry-After header.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              code: rate_limited
              message: Too many requests. Retry in 12 seconds.
    InternalError:
      description: Internal error — safe to retry with backoff.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              code: internal_error
              message: Something went wrong on our side.
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: opaque
      description: >-
        Morph API key, passed as `Authorization: Bearer sk-...`. Create keys at
        https://www.morphllm.com/dashboard/api-keys.

````