Models API

Training and inference endpoints

Complete API reference for training custom models, managing training jobs, and running inference with MotteRL.

Training Endpoints

POST

/api/training/start

Start a new model training job with custom reward functions.

Request Body

{
  "model": "qwen-2.5-7b",
  "learningRate": 0.01,
  "iterations": 100,
  "batchSize": 8,
  "multiStep": false,
  "rewardFunction": "def reward_fn(completion, **kwargs):\n    response = completion[0].get('content', '')\n    expected = kwargs.get('expected_result', '')\n    return 1.0 if expected.lower() in response.lower() else 0.0",
  "trainingData": [
    {
      "prompt": "What is artificial intelligence?",
      "expected_result": "AI is the simulation of human intelligence in machines"
    },
    {
      "prompt": "Define machine learning",
      "expected_result": "ML is a subset of AI that learns from data"
    }
  ]
}

Response

{
  "job_id": "train_abc123",
  "status": "queued",
  "model": "qwen-2.5-7b",
  "estimated_duration": "2-4 hours",
  "created_at": "2024-01-15T10:30:00Z"
}

Parameters

ParameterTypeRequiredDescription
modelstringYesModel to train
learningRatenumberNoLearning rate (0.001-0.1)
iterationsnumberNoTraining iterations (50-500)
rewardFunctionstringYesPython reward function
trainingDataarrayYesTraining examples
GET

/api/training/status/{job_id}

Get the current status and progress of a training job.

Response

{
  "job_id": "train_abc123",
  "status": "training",
  "progress": 0.75,
  "current_iteration": 75,
  "total_iterations": 100,
  "metrics": {
    "average_reward": 0.82,
    "loss": 0.15,
    "learning_rate": 0.01
  },
  "estimated_completion": "2024-01-15T14:30:00Z",
  "logs_url": "/api/training/logs/train_abc123"
}
GET

/api/training/logs/{job_id}

Retrieve detailed training logs and metrics.

Response

{
  "job_id": "train_abc123",
  "logs": [
    {
      "timestamp": "2024-01-15T10:30:00Z",
      "level": "INFO",
      "message": "Training started with 100 examples"
    },
    {
      "timestamp": "2024-01-15T10:35:00Z",
      "level": "INFO",
      "message": "Iteration 10/100 - Loss: 0.45, Reward: 0.62"
    }
  ],
  "metrics_history": [
    {"iteration": 1, "loss": 0.8, "reward": 0.3},
    {"iteration": 10, "loss": 0.45, "reward": 0.62},
    {"iteration": 20, "loss": 0.32, "reward": 0.75}
  ]
}
DELETE

/api/training/cancel/{job_id}

Cancel a running training job.

Response

{
  "job_id": "train_abc123",
  "status": "cancelled",
  "message": "Training job cancelled successfully"
}

Model Management

GET

/api/models

List all available models and your trained models.

Response

{
  "base_models": [
    {
      "id": "qwen-2.5-7b",
      "name": "Qwen 2.5 7B",
      "parameters": "7B",
      "description": "General purpose multilingual model",
      "training_time": "2-4 hours"
    },
    {
      "id": "phi-3.5-mini",
      "name": "Phi 3.5 Mini",
      "parameters": "3.8B",
      "description": "Fast inference optimized model",
      "training_time": "1-2 hours"
    }
  ],
  "custom_models": [
    {
      "id": "model_abc123",
      "name": "Customer Support Agent",
      "base_model": "qwen-2.5-7b",
      "created_at": "2024-01-15T10:30:00Z",
      "status": "ready"
    }
  ]
}
POST

/api/models/{model_id}/inference

Run inference with a trained model.

Request Body

{
  "prompt": "How can I help you with your order?",
  "max_tokens": 150,
  "temperature": 0.7,
  "context": {
    "customer_id": "cust_123",
    "order_id": "order_456"
  }
}

Response

{
  "model_id": "model_abc123",
  "response": "I'd be happy to help you with your order! Let me look up the details for order #456. I can see that your order is currently being processed and should ship within 1-2 business days. Is there anything specific you'd like to know about your order?",
  "tokens_used": 45,
  "processing_time": 1.2,
  "confidence": 0.89
}

Supported Models

ModelParametersBest ForTraining TimeCost/Hour
Qwen 2.5 7B7 billionGeneral purpose, multilingual2-4 hours$2.50
Phi 3.5 Mini3.8 billionFast inference, mobile1-2 hours$1.50
Llama 3.1 8B8 billionCode generation, reasoning3-5 hours$3.00
Mistral 7B7 billionInstruction following2-3 hours$2.00

Error Codes

TRAINING_FAILED

Training job failed due to invalid parameters or data issues.

INSUFFICIENT_CREDITS

Not enough credits to start training. Please add credits to your account.

MODEL_NOT_FOUND

The specified model ID does not exist or is not accessible.

INVALID_REWARD_FUNCTION

The provided reward function contains syntax errors or invalid operations.