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

# Preview tokenized data

> Preview how sampled rows from a fine-tuning training file will be tokenized before packing.



## OpenAPI

````yaml openapi.yaml POST /fine-tunes/preview
openapi: 3.1.0
info:
  title: Together APIs
  description: The Together REST API. See https://docs.together.ai for more details.
  version: 2.0.0
  termsOfService: https://www.together.ai/terms-of-service
  contact:
    name: Together Support
    url: https://www.together.ai/contact
  license:
    name: MIT
    url: https://github.com/togethercomputer/openapi/blob/main/LICENSE
servers:
  - url: https://api.together.ai/v1
    description: Default environment for APIs
  - url: https://api-inference.together.ai/v2
    description: Optimized environment for inference
security:
  - bearerAuth: []
paths:
  /fine-tunes/preview:
    post:
      tags:
        - Fine-tuning
      summary: Preview tokenized data
      description: >-
        Preview how sampled rows from a fine-tuning training file will be
        tokenized before packing.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/FineTunePreviewRequest'
      responses:
        '200':
          description: Tokenized data preview generated successfully
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/FineTunePreviewResponse'
        '400':
          description: Invalid request or unsupported dataset for preview.
          content:
            application/json:
              schema:
                oneOf:
                  - $ref: '#/components/schemas/FineTunePreviewMessageError'
                  - $ref: '#/components/schemas/FineTunePreviewDetailError'
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorData'
        '404':
          description: Training file not found.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorData'
        '500':
          description: Internal Server Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/FineTunePreviewMessageError'
        '502':
          description: Preview service unavailable.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/FineTunePreviewMessageError'
        '503':
          description: Preview service is at capacity.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/FineTunePreviewDetailError'
      x-codeSamples:
        - lang: Python
          label: Together AI SDK (Python)
          source: |
            from together import Together

            client = Together()

            preview = client.fine_tuning.preview(
                model="meta-llama/Meta-Llama-3.1-8B-Instruct-Reference",
                training_file="<FILE_ID>",
            )
            print(preview)
        - lang: TypeScript
          label: Together AI SDK (TypeScript)
          source: |
            import Together from "together-ai";

            const client = new Together();

            const preview = await client.fineTuning.preview({
              model: "meta-llama/Meta-Llama-3.1-8B-Instruct-Reference",
              training_file: "<FILE_ID>",
            });
            console.log(preview);
        - lang: JavaScript
          label: Together AI SDK (JavaScript)
          source: |
            import Together from "together-ai";

            const client = new Together();

            const preview = await client.fineTuning.preview({
              model: "meta-llama/Meta-Llama-3.1-8B-Instruct-Reference",
              training_file: "<FILE_ID>",
            });
            console.log(preview);
components:
  schemas:
    FineTunePreviewRequest:
      type: object
      description: Request body for previewing tokenized fine-tuning data.
      required:
        - model
        - training_file
      properties:
        model:
          type: string
          description: >-
            Name of the base model whose tokenizer and chat template will be
            used.
        training_file:
          type: string
          description: File-ID of the uploaded JSONL training file to sample for preview.
        training_method:
          type: string
          default: sft
          enum:
            - sft
          description: >-
            Fine-tuning method to preview. Only supervised fine-tuning is
            currently supported.
        train_on_inputs:
          type: boolean
          default: false
          description: >-
            Whether prompt or user-message tokens should contribute to training
            loss in the preview.
        top_k:
          type: integer
          default: 5
          minimum: 1
          maximum: 50
          description: >-
            Maximum number of rows from the start of the training file to
            tokenize.
    FineTunePreviewResponse:
      type: object
      description: Tokenized preview for sampled rows from a fine-tuning training file.
      required:
        - model
        - dataset_format
        - max_seq_length
        - train_on_inputs
        - rows
      properties:
        model:
          type: string
          description: Name of the base model used to tokenize the sampled rows.
        dataset_format:
          type: string
          enum:
            - general
            - conversation
            - instruction
          description: Detected SFT dataset format for the sampled rows.
        max_seq_length:
          type: integer
          description: Maximum sequence length configured for the requested model.
        train_on_inputs:
          type: boolean
          description: Whether prompt or user-message tokens contribute to training loss.
        rows:
          type: array
          description: >-
            Tokenized preview rows, in the same order as the sampled training
            file rows.
          items:
            $ref: '#/components/schemas/FineTunePreviewRow'
    FineTunePreviewMessageError:
      type: object
      description: >-
        Error response with a message field returned by the fine-tuning API
        layer.
      required:
        - message
      properties:
        message:
          type: string
          description: Human-readable error message.
    FineTunePreviewDetailError:
      type: object
      description: >-
        Error response with a detail field returned by the preview tokenization
        service.
      required:
        - detail
      properties:
        detail:
          type: string
          description: Human-readable error detail.
    ErrorData:
      type: object
      required:
        - error
      properties:
        error:
          type: object
          properties:
            message:
              type: string
              nullable: false
            type:
              type: string
              nullable: false
            param:
              type: string
              nullable: true
              default: null
            code:
              type: string
              nullable: true
              default: null
          required:
            - type
            - message
    FineTunePreviewRow:
      type: object
      description: Tokenized representation of one sampled fine-tuning row.
      required:
        - input_ids
        - tokens
        - labels
        - trained_spans
        - num_tokens
        - num_trained_tokens
        - truncated
      properties:
        input_ids:
          type: array
          description: Token IDs produced for the sampled row.
          items:
            type: integer
            description: Token ID from the model tokenizer.
        tokens:
          type: array
          description: Raw token strings produced for the sampled row.
          items:
            type: string
            description: Token text from the model tokenizer.
        labels:
          type: array
          description: Training labels for each token; masked tokens use -100.
          items:
            type: integer
            description: Label value for the token at the same position.
        trained_spans:
          type: array
          description: Half-open token index ranges that contribute to training loss.
          items:
            type: array
            minItems: 2
            maxItems: 2
            description: Start and end token indexes for one trained span.
            items:
              type: integer
              description: Token index in the row.
        num_tokens:
          type: integer
          description: Total number of tokens in the preview row after truncation.
        num_trained_tokens:
          type: integer
          description: Number of tokens in the row that contribute to training loss.
        truncated:
          type: boolean
          description: Whether the row was truncated to the model maximum sequence length.
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      x-bearer-format: bearer
      x-default: default

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.