diff --git a/README.md b/README.md index c252450a..d4571600 100644 --- a/README.md +++ b/README.md @@ -102,6 +102,8 @@ Here is an example of how to use the mlflow.js library to create an exper import Mlflow from 'mlflow-js'; // Initialize the MLflow client +// If your tracking server requires a token please also set env variable MLFLOW_TRACKING_TOKEN +// export MLFLOW_TRACKING_TOKEN = "{token}" const mlflow = new Mlflow(process.env.MLFLOW_TRACKING_URI); // Create a new experiment diff --git a/mlflow/lib/utils/apiRequest.js b/mlflow/lib/utils/apiRequest.js index b5690d5e..7a7b63db 100644 --- a/mlflow/lib/utils/apiRequest.js +++ b/mlflow/lib/utils/apiRequest.js @@ -15,6 +15,10 @@ export async function apiRequest(baseUrl, endpoint, options) { 'Content-Type': 'application/json', }, }; + // Add MLflow tracking token if it exists + if (process.env.MLFLOW_TRACKING_TOKEN) { + fetchOptions.headers['Authorization'] = `Bearer ${process.env.MLFLOW_TRACKING_TOKEN}`; + } if (body) { fetchOptions.body = JSON.stringify(body); } @@ -26,4 +30,4 @@ export async function apiRequest(baseUrl, endpoint, options) { const data = (await response.json()); return { response, data }; } -//# sourceMappingURL=apiRequest.js.map \ No newline at end of file +//# sourceMappingURL=apiRequest.js.map