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

# Fit a Model

> **Deprecated:** Prefer the TabPFN client (`tabpfn-client`) or `POST /tabpfn/fit` after preparing uploads. This multipart `/v1/fit` surface is legacy. See the [TabPFN-3 changelog](/changelog/tabpfn-3).

Uploads and fits a TabPFN model on your training data. The API automatically handles preprocessing and stores a reference to your trained context (not the model weights). You can use either a single dataset file (with the target column included) or separate feature and label files.



## OpenAPI

````yaml /api-reference/openapi.json post /v1/fit
openapi: 3.1.0
info:
  title: TabPFN API
  description: >-
    Prior Labs TabPFN API. **Prefer
    [tabpfn-client](https://github.com/PriorLabs/tabpfn-client)**. Current
    integration surface: **`/tabpfn/*` JSON routes** (prepare uploads, fit,
    predict, limits). **`/v1/*` multipart routes are deprecated.** See the
    [Changelog](/changelog).
  version: 2.0.0
  contact:
    name: Prior Labs
    email: hello@priorlabs.ai
servers:
  - url: https://api.priorlabs.ai
    description: Production TabPFN API (`/tabpfn/*` current; `/v1/*` deprecated)
security:
  - BearerAuth: []
paths:
  /v1/fit:
    post:
      tags:
        - Training
      summary: Fit a Model
      description: >-
        **Deprecated:** Prefer the TabPFN client (`tabpfn-client`) or `POST
        /tabpfn/fit` after preparing uploads. This multipart `/v1/fit` surface
        is legacy. See the [TabPFN-3 changelog](/changelog/tabpfn-3).


        Uploads and fits a TabPFN model on your training data. The API
        automatically handles preprocessing and stores a reference to your
        trained context (not the model weights). You can use either a single
        dataset file (with the target column included) or separate feature and
        label files.
      operationId: fit_v1_deprecated
      requestBody:
        required: true
        content:
          multipart/form-data:
            schema:
              type: object
              required:
                - data
              properties:
                data:
                  type: string
                  description: >-
                    A JSON string defining the training configuration. 


                    **Supported Systems**: 

                    - `["preprocessing"]` - Applies skrub preprocessing, 

                    - `["text"]` - Adds text embeddings for text columns. 


                    **Default**: `["preprocessing", "text"]`. 


                    **Supported Config Parameters**:

                    - `n_estimators` (`int`, 1-10) - Number of ensemble
                    estimators, 

                    - `softmax_temperature` (`float`) - Temperature for softmax
                    scaling, 

                    - `average_before_softmax` (`bool`) - Average before
                    softmax,

                    - `ignore_pretraining_limits` (`bool`) - Ignore pretraining
                    limits, 

                    - `random_state` (`int`) - Random seed for reproducibility.
                dataset_file:
                  type: string
                  format: binary
                  description: >-
                    **Option 1:** CSV file containing both features (`X_train`)
                    and labels (`y_train`). Use this when you have **all data in
                    a single file**.
                features_file:
                  type: string
                  format: binary
                  description: >-
                    **Option 2:**: CSV file containing only feature columns
                    (`X_train`). Must be used together with `labels_file`.
                labels_file:
                  type: string
                  format: binary
                  description: >-
                    **Option 2:** CSV file containing only the target/label
                    column (`y_train`). Must be used together with
                    `features_file`.
              oneOf:
                - required:
                    - data
                    - dataset_file
                - required:
                    - data
                    - features_file
                    - labels_file
            examples:
              single_dataset:
                summary: Single CSV file (features + target)
                value:
                  data: '{"task": "classification", "schema": {"target": "churn"}}'
                  dataset_file: '[binary data]'
              separate_files:
                summary: Separate features and labels files
                value:
                  data: '{"task": "regression", "schema": {"target": "price"}}'
                  features_file: '[binary data]'
                  labels_file: '[binary data]'
      responses:
        '200':
          description: >-
            Model fitted successfully — returns a model ID for later prediction
            calls.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/FitResponse'
              example:
                model_id: 123e4567-e89b-12d3-a456-426614174000
                task: classification
        '400':
          description: Invalid request — missing data or malformed input.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                code: error.bad_request
                detail: Invalid request data
                retryable: false
                support: https://discord.com/invite/VJRuU3bSxt
        '401':
          description: >-
            Unauthorized — authentication required or credentials invalid.


            **Possible causes:**

            - Missing or malformed `Authorization` header

            - Invalid or expired JWT token

            - User not found (token references a deleted account)

            - JWT decode errors (JWEDecodeError, JWTDecodeError, JWTClaimsError)


            **Examples:**

            - Missing token: `{"detail": "Not authenticated"}`

            - Invalid credentials: `{"detail": "Could not validate
            credentials"}`
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                missing_token:
                  value:
                    code: auth.unauthorized
                    detail: Not authenticated
                    retryable: false
                    support: https://discord.com/invite/VJRuU3bSxt
                invalid_credentials:
                  value:
                    code: auth.unauthorized
                    detail: Could not validate credentials
                    retryable: false
                    support: https://discord.com/invite/VJRuU3bSxt
                expired_token:
                  value:
                    code: auth.unauthorized
                    detail: Invalid or expired JWT token
                    retryable: false
                    support: https://discord.com/invite/VJRuU3bSxt
        '403':
          description: >-
            Forbidden — user account not verified or insufficient permissions.


            **Possible causes:**

            - Valid token for an unverified user

            - Account not yet verified via email


            **Example response:**

            `{"code": "auth.forbidden", "detail": "User account not verified",
            "retryable": false, "support":
            "https://discord.com/invite/VJRuU3bSxt"}`
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                code: auth.forbidden
                detail: User account not verified
                retryable: false
                support: https://discord.com/invite/VJRuU3bSxt
        '422':
          description: Validation error — one or more fields are incorrectly formatted.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ValidationError'
      deprecated: true
      security:
        - BearerAuth: []
      x-codeSamples:
        - lang: python
          label: Single CSV upload
          source: |-
            import os, json, requests

            # Define your dataset path
            train_path = "train.csv"

            # Get your API key from the environment
            api_key = os.getenv("PRIORLABS_API_KEY")
            headers = {"Authorization": f"Bearer {api_key}"}

            # Upload your training dataset to /v1/fit
            payload = {
                 "task": "classification",
                 "schema": {
                     "target": "churn",
                     "description": "Customer churn dataset"
                 }
            }

            files = {
                 "data": (None, json.dumps(payload), "application/json"),
                 "dataset_file": (train_path, open(train_path, "rb")),
            }

            fit_response = requests.post(
                 "https://api.priorlabs.ai/v1/fit",
                 headers=headers,
                 files=files,
            )

            model_id = fit_response.json().get("model_id")
            print(f"✅ Model trained: {model_id}")
        - lang: python
          label: Separate features + labels
          source: |-
            import os, json, requests

            # Define your file paths
            X_train_path = "X_train.csv"  # features only
            y_train_path = "y_train.csv"  # labels only

            # Get your API key from the environment
            api_key = os.getenv("PRIORLABS_API_KEY")
            headers = {"Authorization": f"Bearer {api_key}"}

            # Upload your training dataset with separate files
            payload = {
                "task": "regression",
                "schema": {
                    "target": "price",
                    "description": "House price prediction dataset"
                }
            }

            files = {
                "data": (None, json.dumps(payload), "application/json"),
                "features_file": (X_train_path, open(X_train_path, "rb")),
                "labels_file": (y_train_path, open(y_train_path, "rb")),
            }

            fit_response = requests.post(
                "https://api.priorlabs.ai/v1/fit",
                headers=headers,
                files=files,
            )

            model_id = fit_response.json().get("model_id")
            print(f"✅ Model trained: {model_id}")
components:
  schemas:
    FitResponse:
      type: object
      required:
        - model_id
        - task
      properties:
        model_id:
          type: string
          format: uuid
          description: Unique identifier for the fitted model (used for prediction calls).
        task:
          $ref: '#/components/schemas/PredictionTask'
      example:
        model_id: 123e4567-e89b-12d3-a456-426614174000
        task: classification
    ErrorResponse:
      type: object
      required:
        - code
        - detail
        - retryable
        - support
      properties:
        code:
          type: string
          description: Error category code (e.g., auth.unauthorized, rate.limit.exceeded)
          example: auth.unauthorized
        detail:
          type: string
          description: Human-readable error message describing what went wrong.
          example: Invalid authentication credentials
        retryable:
          type: boolean
          description: Indicates whether the request can be retried.
          example: false
        support:
          type: string
          description: URL to get support for this error.
          example: https://discord.com/invite/VJRuU3bSxt
      example:
        code: auth.unauthorized
        detail: Invalid authentication credentials
        retryable: false
        support: https://discord.com/invite/VJRuU3bSxt
    ValidationError:
      type: object
      required:
        - code
        - detail
        - errors
        - retryable
        - support
      properties:
        code:
          type: string
          description: Error category code for validation errors
          example: validation.failed
        detail:
          type: string
          description: Human-readable validation error message
          example: Validation error for FitRequest
        errors:
          type: array
          description: Array of field-level validation errors
          items:
            type: object
            properties:
              field:
                type: string
                description: Field name where the error occurred
                example: task
              message:
                type: string
                description: Error message for this field
                example: field required
        retryable:
          type: boolean
          description: Indicates whether the request can be retried
          example: false
        support:
          type: string
          description: URL to get support for this error
          example: https://discord.com/invite/VJRuU3bSxt
      example:
        code: validation.failed
        detail: Validation error for FitRequest
        errors:
          - field: task
            message: field required
          - field: systems
            message: >-
              Invalid system: invalid_system. Must be one of: ['preprocessing',
              'text']
        retryable: false
        support: https://discord.com/invite/VJRuU3bSxt
    PredictionTask:
      type: string
      enum:
        - classification
        - regression
      description: >-
        Specifies the type of task to perform — either classification or
        regression.
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
      description: >-
        Bearer token for authentication, obtained after signing up and
        generating an API key.

````