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

# Introdução à API

> Use o AITraining programaticamente com Python

# API Python

O AITraining fornece uma API Python para acesso programático a toda a funcionalidade de treinamento.

## Instalação

```bash theme={null}
pip install aitraining torch
```

## Início Rápido

```python theme={null}
from autotrain.trainers.clm.params import LLMTrainingParams
from autotrain.project import AutoTrainProject

# Configure training
params = LLMTrainingParams(
    model="google/gemma-3-270m",
    data_path="./data.jsonl",
    project_name="my-model",
    trainer="sft",
    epochs=3,
    batch_size=4,
    lr=2e-5,
    peft=True,
    lora_r=16,
)

# Start training
project = AutoTrainProject(params=params, backend="local", process=True)
job_id = project.create()
print(f"Training started: {job_id}")
```

## Estrutura da API

### Parâmetros de Treinamento

Cada tipo de tarefa tem sua própria classe de parâmetros:

| Tarefa                  | Classe de Parâmetros        |
| ----------------------- | --------------------------- |
| Treinamento de LLM      | `LLMTrainingParams`         |
| Classificação de Texto  | `TextClassificationParams`  |
| Classificação de Imagem | `ImageClassificationParams` |
| Classificação de Token  | `TokenClassificationParams` |
| Seq2Seq                 | `Seq2SeqParams`             |
| Tabular                 | `TabularParams`             |
| Detecção de Objetos     | `ObjectDetectionParams`     |
| VLM                     | `VLMTrainingParams`         |

### Execução do Projeto

```python theme={null}
from autotrain.project import AutoTrainProject

# Create project
project = AutoTrainProject(
    params=params,
    backend="local",  # or "spaces"
    process=True      # Start immediately
)

# Run training
job_id = project.create()
```

## Exemplo: Script Completo de Treinamento

```python theme={null}
from autotrain.trainers.clm.params import LLMTrainingParams
from autotrain.project import AutoTrainProject

def train_model():
    # Configure parameters
    params = LLMTrainingParams(
        # Model
        model="meta-llama/Llama-3.2-1B",
        project_name="llama-sft",

        # Data
        data_path="./conversations.jsonl",
        train_split="train",
        text_column="text",
        block_size=2048,

        # Training
        trainer="sft",
        epochs=3,
        batch_size=2,
        gradient_accumulation=4,
        lr=2e-5,
        mixed_precision="bf16",

        # LoRA
        peft=True,
        lora_r=16,
        lora_alpha=32,
        lora_dropout=0.05,

        # Logging
        log="wandb",
        logging_steps=10,
    )

    # Start training
    project = AutoTrainProject(
        params=params,
        backend="local",
        process=True
    )

    return project.create()

if __name__ == "__main__":
    job_id = train_model()
    print(f"Training complete: {job_id}")
```

## Módulos Principais

| Módulo                                          | Descrição                 |
| ----------------------------------------------- | ------------------------- |
| `autotrain.project`                             | Execução do projeto       |
| `autotrain.trainers.clm.params`                 | Parâmetros de LLM         |
| `autotrain.trainers.text_classification.params` | Classificação de texto    |
| `autotrain.dataset`                             | Manipulação de datasets   |
| `autotrain.generation`                          | Utilitários de inferência |

## Próximos Passos

<CardGroup cols={2}>
  <Card title="LLM Endpoints" href="/api/llm-endpoints">
    API de treinamento LLM
  </Card>

  <Card title="Python SDK" href="/api/python-sdk">
    Referência completa do SDK
  </Card>
</CardGroup>
