Define Ports and Domains

When you create a Service, you need to specify the ports that the Service will listen on. You can decide to expose a port in which case you will have to attach a domain to the service.

Not exposing the port

If you do not expose a service, you get a URL of the form servicename-workspacename.svc.cluster.local:port which can only be called from services within the cluster.

Exposing the port

This will enable the service to be called from anywhere using the endpoint - other users or services living outside your cluster will also be able to access it. In this case, you will need to map a domain URL to your service. TrueFoundry supports both host-based routing and path-based routing.

If you use host-based routing, two services s1 and s2 will have URLs of the form and

In the case of path-based routing, the URLs will be of the form and If you decide to enable path-based routing, please ensure the application that you have deployed supports path-based routing.

Domains are configured in the cluster. You can view which domains are accessible to you from here.

Host-based routing will be preferred especially if you are deploying some UI-based applications.

Configuring the Port for your Service

Via the User Interface (UI)

Via the Python SDK

The Service class has a ports argument where you can pass a list of Port objects. Each Port object represents a port that the service will listen on. In the Port field you can specify the Port Number, host for your Endpoint and Path (Optional)


Picking a value for host

Providing a host value depends on the base domain urls configured in the cluster settings, you can learn how to find the base domain urls available to you here

For e.g. If your base domain url is * then a valid value can be

Alternatively if you have a non wildcard based domain url e.g., then a valid value can be

import logging

from servicefoundry import Build, Service, DockerFileBuild, Port

service = Service(
+   ports=[
+       Port(
+           port=8080,
+           # Uses subdomain based routing
+           host="",
+           # Alternatively we can use path based routing - E.g.
+           # host="",
+           path="/fastapi/v1/"
+       )
+   ]

What if you don't know which port to use?

Usually, most of the commonly used applications will come with a way to define the port. We have listed it for some of the most commonly used frameworks in ML.

FastAPI (Uvicorn) - Default port is 8000. This can be overridden using the command uvicorn main:app --port 8001

Gradio App - Launch your Gradio app as follows and enter the port number 8080."", port=8080)

Now you need to specify the same port number in the service configuration. In this case 8080

Streamlit - Default port is 8501.

Adding Basic authentication to Service

Ideally when deploying a Service it is a good idea to protect publicly exposed ports using some form of authentication. You can add a username password based authentication to your endpoints.

Via the User Interface (UI)

Via the Python SDK

We can add basic (username and password) authentication to a Port of the Service in the Python definition using servicefoundry.BasicAuthCreds )

from servicefoundry import Build, Service, Port, BasicAuthCreds, DockerFileBuild

service = Service(
+           auth=BasicAuthCreds(
+                username="hello",
+                password="pass"
+           )

Sending request to your Authenticated Endpoint

Upon deploying the service, the endpoint will now display a padlock 🔒 icon, indicating that authentication is required for access.

Browser Access

When attempting to access the endpoint from a web browser, you will be prompted to enter your credentials.

Python Access

When using Python, you can pass the credentials in the following manner:

import requests

endpoint = ''

response = requests.get(endpoint, auth=('hello', 'pass'))

Curl Access

When using cURL, you'll need to include the credentials as part of the command:

curl -v -X GET --user hello:pass