DeepFellow DOCS

Custom Service

Run ML models and microservices as Docker containers and expose them as tools in DeepFellow.

The Custom Service lets you run any containerized application — an ML model, a microservice, or any HTTP API — directly on DeepFellow Infra. Once installed, the service is accessible through the /custom/{prefix}/{path} endpoint and can be connected to an LLM as a tool.

Available Models

The following models are ready to install from the Custom Service panel in DeepFellow Infra Web Panel:

Model IDDescription
lemmatizerMultilingual text lemmatization API.
bentoml/example-summarizationText summarization service built with BentoML.
deepfellow-bge-m3High-performance multilingual text embeddings model for sparse vectors.
deepfellow-finetuneLLM LoRA fine-tuning framework with an OpenAI-compatible fine-tuning job queue.
doc_chunkerConverts many file types (PDF, XLSX, MP3, and others) into text chunks suitable for vector search.
easyOCROptical character recognition service that extracts text from images and binary data.
glinerNamed-entity-recognition API used for Knowledge Graph extraction.

To install one of these models:

Open DeepFellow Infra Web Panel and go to Services.

Locate the custom service and click Install if it is not already installed.

Click custom → Models, then find the model you want.

Click Install next to the model.

Add Your Own Model

You can run any containerized ML model or microservice in the Custom Service. This section walks through a complete example using an Iris species classifier.

Requirements

1. Train the Model

Create and save a trained ML model as a .pkl file. The example uses scikit-learn:

from sklearn.datasets import load_iris
from sklearn.ensemble import RandomForestClassifier
from sklearn.model_selection import train_test_split
import joblib

iris = load_iris()
X, y = iris.data, iris.target
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)

model = RandomForestClassifier(n_estimators=100, random_state=42)
model.fit(X_train, y_train)

joblib.dump(model, "iris_model.pkl")

Run it with:

uv run python create_iris_model.py

2. Create a Microservice

Wrap the model in a web API. The example uses FastAPI on port 8001:

from fastapi import FastAPI, HTTPException
import joblib
from pydantic import BaseModel
from typing import List
import numpy

app = FastAPI()
model = joblib.load("iris_model.pkl")

class InputData(BaseModel):
    features: List[float]

@app.post("/predict")
def predict(data: InputData) -> dict[str, int]:
    prediction: numpy.ndarray = model.predict([data.features])
    return {"prediction": prediction.tolist()[0]}

@app.get("/health")
def health() -> dict[str, str]:
    return {"status": "ok"}

@app.get("/test_model")
def test_model() -> dict[str, int]:
    # A working model classifies this Iris setosa sample as class 0.
    prediction = model.predict([[5.1, 3.5, 1.4, 0.2]]).tolist()[0]
    if prediction != 0:
        raise HTTPException(status_code=503, detail=f"Expected class 0, got {prediction}")
    return {"prediction": prediction}

The /health and /test_model routes let DeepFellow Infra check the model when you click Test in the Web Panel. For details, see Testing Custom Models.

3. Write a Dockerfile

Package the microservice in a Docker image:

FROM python:3.11-slim

COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/

WORKDIR /app

COPY pyproject.toml uv.lock ./
RUN uv sync --frozen --no-dev

COPY . .

EXPOSE 8001

CMD ["uv", "run", "uvicorn", "app:app", "--host", "0.0.0.0", "--port", "8001"]

4. Build the Docker Image

docker build -t iris-model .

You are not limited to locally built images. In the Docker image field you can also enter an image tag from Docker Hub or GitHub Container Registry.

5. Install on DeepFellow Infra

Open DeepFellow Infra Web Panel and go to Services → custom → Install.

Click custom → Add custom model.

Fill in the form: Model ID iris-model, Docker image iris-model, Docker image port 8001.

Click Add, then Install.

Enter iris-model as the endpoint prefix when prompted.

Wait for the model to appear in the list with a green Installed label.

6. Verify

Send a request to the DeepFellow Infra endpoint:

curl -X POST 'http://DEEPFELLOW_INFRA_HOST/custom/iris-model/predict' \
  -H 'Authorization: Bearer DF_INFRA_API_KEY' \
  -H 'Content-Type: application/json' \
  -d '{"features": [5.1, 3.5, 1.4, 0.2]}'

Expected response:

{"prediction": 0}

To check the model from DeepFellow Infra Web Panel, click Test on its model card.

Use as a Tool

To expose this model to an LLM, add it as a custom-mcp tool. See Using Tools for the full schema and a complete example using this iris classifier.

Testing Custom Models

To check that an installed custom model works, click Test on its model card in DeepFellow Infra Web Panel. DeepFellow Infra sends GET requests to the following routes of the model, through its /custom/{prefix} endpoint and in this order:

RoutePurposeIf the route returns 404
/healthHealth checkDeepFellow Infra sends GET /healthz instead.
/healthzHealth check under an alternative nameThe model has no health check.
/test_modelSelf-test you define in your image (optional)The model has no self-test.

The test passes if at least one of these routes exists and every route that exists returns 200:

  • If the health check returns a status other than 200 or 404, the test fails and DeepFellow Infra doesn't call /test_model.
  • If /test_model returns a status other than 200 or 404, the test fails.
  • If none of the routes exists, the test fails.
  • If the model's container doesn't accept connections, for example because it's still starting, the test fails with Model unreachable.

The test result shows the response of /test_model, or the response of the health check if the model has no self-test. If that response is empty, the result shows passed for /test_model or healthy for the health check.

Self-Test Route

A health check shows that the service runs. To check that the model itself returns correct results, add a GET /test_model route to your image, as in the Iris example. The route must meet the following requirements:

  • Accept a GET request without a body.
  • Return 200 when the model works, and a status other than 404, for example 503, when it doesn't. DeepFellow Infra reads 404 as an image without a self-test, so a broken model that returns 404 passes the test on the health check alone.
  • Return a short text or JSON verdict of at most 64 KB, not media such as audio or images.
  • Respond quickly. The whole test, all routes together, has a limit of 30 seconds.
  • Change no data: no writes, deletes, or resets.

Like every route of a custom model, /test_model is reachable at /custom/{prefix}/test_model for anyone who holds a DeepFellow Infra API key. Keep the route cheap to call, and don't return secrets, environment variables, or internal paths in its response.

A passing test shows that the model responds. It doesn't show that the Docker image is safe to run. Install images only from sources you trust.

Edit and Duplicate

Open the ⋮ menu on an installed model's card and click Edit Settings to change its configuration: the endpoint prefix, the Docker image, environment variables, or any other install-time option. DeepFellow uninstalls the running model, applies the new settings, and reinstalls it automatically.

To move a model to the newest version of its Docker image without opening the form, click Update in the same menu. See Updating Models.

  • The Model ID cannot be changed from the Edit dialog. To register the model under a different ID, use Duplicate instead.
  • If the endpoint prefix you enter is already used by another installed model, DeepFellow rejects the edit before uninstalling anything.
  • Saving an edit with no changes closes the dialog without uninstalling and reinstalling the model.

To create an independent copy of a model instead of changing the original, select Save as a new service in the Edit dialog before saving. DeepFellow installs the copy immediately, under the ID and prefix you provide, with the same settings as the original.

Proxy Timeout

Every custom-service install form, whether for a catalog model or a model you add yourself, includes a Seconds the proxy waits for a response from this service before timing out field. It controls how long the proxy waits for that specific service to respond before timing out the request.

Leave the field empty to use the model's own default proxy timeout, which the field description shows. A model without one uses the standard_proxy_timeout_seconds setting (600 seconds by default). Of the catalog models, doc_chunker declares its own default of 7200 seconds, since it answers only once a whole file is converted. Set the field to a higher value for a service with a long processing time, or to a lower value for a fast service, so a failure is detected sooner. The value you enter applies only to that one installation and doesn't change the global default used by other services.

Send Requests to One Instance

When the same custom model runs on several instances, locally or across a Mesh, DeepFellow Infra picks the instance for each request. For details, see Request Routing Between Instances. A stateful service, for example one with a job queue, keeps each job on the instance that created it. If a later request of the same job reaches another instance, that instance answers that the job doesn't exist.

To keep all requests of one job on one instance, use the route that DeepFellow Infra returns in the X-DF-Route response header. The route names the instance that served the request. A request that carries the route in its own X-DF-Route header goes straight to that instance, also when the instance runs on another node of the Mesh. DeepFellow Infra doesn't pick an instance for such a request.

Send the first request of the job without the X-DF-Route header:

curl -i -X POST 'http://DEEPFELLOW_INFRA_HOST/custom/MODEL_PREFIX/jobs' \
  -H 'Authorization: Bearer DF_INFRA_API_KEY' \
  -H 'Content-Type: application/json' \
  -d '{"input": "Text to process"}'

Read the route from the X-DF-Route header of the response:

HTTP/1.1 200 OK
X-DF-Route: ROUTE

Send every next request of the job with the route in the X-DF-Route header:

curl -X GET 'http://DEEPFELLOW_INFRA_HOST/custom/MODEL_PREFIX/jobs/JOB_ID' \
  -H 'Authorization: Bearer DF_INFRA_API_KEY' \
  -H 'X-DF-Route: ROUTE'

Treat the route as an opaque value. Copy it from a response, and don't build it or parse it yourself.

Unavailable Routes

If the instance named by the route isn't available, DeepFellow Infra returns 503 with the route_unavailable error code. It doesn't send the request to another instance:

{
  "error": {
    "message": "Route ROUTE is not available for prefix MODEL_PREFIX",
    "type": "api_error",
    "param": null,
    "code": "route_unavailable"
  }
}

The route is unavailable in the following situations:

  • The connection to the Mesh node that runs the instance drops. The node tries to reconnect every 10 seconds.
  • DeepFellow Infra restarts, and the model hasn't loaded yet.
  • The model has a new route, so the old route no longer exists. See Route Lifetime.
  • The route belongs to another model's prefix.

To handle route_unavailable, retry the request with the same route for a limited time. If the route stays unavailable, send the request without the X-DF-Route header, read the new route from the response, and start the job again on the new instance.

Route Lifetime

A model of the custom service or a Finetune instance keeps its route in the following situations:

  • DeepFellow Infra restarts.
  • You edit the custom service with Edit and Save in its settings.
  • You edit a Finetune instance with Edit and Save in its settings. The instance keeps its route even if the edit fails and DeepFellow Infra reverts it.

For more information about editing a service, see Editing a Service.

A model of the custom service or a Finetune instance gets a new route in the following situations:

  • You edit the model with Edit Settings or update it with Update.
  • You uninstall the model or the instance and install it again.

The /custom endpoint of Stable Diffusion gets a new route every time DeepFellow Infra restarts.

A route doesn't keep jobs alive. If the model's container restarts, for example after you edit the custom service, the service loses the jobs in progress. A Finetune instance keeps its jobs in a database outside the container, so it doesn't lose them. After its container restarts, a job in progress starts training again from the beginning.

Limitations

  • Routes apply to /custom endpoints only, including Finetune instances, which DeepFellow Infra serves at /custom/{prefix}.
  • The route_unavailable error carries no X-DF-Route header.
  • If the instance doesn't answer at all, for example because its container refuses the connection or times out, the response carries no X-DF-Route header.
  • Every Mesh node on the path of a request must run a DeepFellow Infra version that supports X-DF-Route. An older node between the client and the instance ignores the header and picks an instance itself.

We use cookies on our website. We use them to ensure proper functioning of the site and, if you agree, for purposes such as analytics, marketing, and targeting ads.

On this page