Self-Hosting an LLM Application Platform: Service Address, Admin API Key, and Workspace ID Configuration

    After deploying an open-source LLM application platform locally or in a private environment, you can automate app creation, deployment, and updates through scripts or automation tools instead of using the web UI manually. This guide explains how to configure the three required items—the service base URL, the administrator API key, and the workspace ID—including where to find each value, key configuration details, and common troubleshooting steps.

    After self-hosting an open-source LLM application platform in a local or private environment, many developers want to create, deploy, and update applications through scripts or automation tools rather than performing every operation manually in the web UI. To enable this automation workflow, three pieces of information must be configured correctly: the service base URL, the administrator API key, and the workspace identifier. This article covers these three areas step by step, explaining how to obtain each value, key configuration points, and how to troubleshoot common issues.

    1. Service Base URL: The Entry Point for Automation

    The first step in any API call is to confirm the server access address. The form of the address varies depending on the deployment method:

    • Local development environment: Usually http://localhost. If a non-default port is used, add the port number, for example http://localhost:8080.
    • Online self-hosted environment: Typically a domain bound through a reverse proxy, such as https://your-domain.example.com. HTTPS is recommended to secure transmission.
    • Cloud-hosted service: A unified API endpoint provided by the service provider, usually available directly in the console documentation.

    To determine the base URL, log in to the platform’s web UI and inspect the URL in the browser address bar. If a custom domain or path has been configured, open a workspace page and remove the trailing route such as /apps. The remaining base portion is the service address you need to enter. Note that the web access URL and the API URL may not be identical. Some deployment types assign a separate path prefix to the API. Before configuring, read the deployment notes for the image or distribution you are using and confirm how the API gateway is exposed.

    2. Administrator API Key: The Key to Permissions

    The administrator key is not generated by clicking a button in the web UI. It is manually set in the server-side configuration file. This is often the first hurdle for beginners: they cannot find the configuration location, or they configure it but it does not take effect.

    2.1 Locate the Configuration File

    Go to the platform deployment directory. The .env file is usually found under the docker subdirectory or the api subdirectory. This file is read at service startup and contains most core environment variable configuration.

    2.2 Add or Confirm Two Settings

    In the .env file, confirm that the following settings exist and are correct:

    1. ADMIN_API_KEY_ENABLE=true
    2. ADMIN_API_KEY=sk-admin-your-custom-string

    The first setting is the switch and must be true to enable administrator authentication. The second is the key itself. Use a sufficiently long random string and avoid weak passwords. If these lines are not present in the file, add them manually and save the file.

    2.3 Restart the Service to Apply the Configuration

    After changing environment variables, you must restart the API process to load the new configuration. Run the command line rather than clicking a “Restart” button in a container management UI:

    1. cd ~/your-deploy-path/docker
    2. docker compose up -d --force-recreate api

    The key parameter here is --force-recreate, which forces the container instance to be recreated and ensures the new environment variables are injected. Restarting a container only through a management panel sometimes does not reload the variables. This is a common reason configuration appears not to take effect.

    2.4 Troubleshoot Common Errors

    If an API call returns 401 Invalid token, check the following in order:

    • Check whether ADMIN_API_KEY_ENABLE is actually set to true.
    • Check whether the key string exactly matches the value sent in the request header, including any extra spaces or quotes.
    • Confirm that the .env file changes were saved.
    • Confirm that the API process was actually restarted, not just the web frontend or another container.

    3. Workspace ID: The Coordinate for Locating Resources

    The workspace ID is the primary key of each record in the database tenant table. It tells automation scripts which workspace to operate in. It is a UUID-format string. There are two ways to obtain it.

    1. Log in to the platform web UI and press F12 to open the developer tools.
    2. Switch to the Network tab and select Fetch/XHR as the filter.
    3. Press F5 to refresh the page, then find the request named workspaces in the request list.
    4. Inspect the response content. The id field is the required workspace ID, in a form like this:
    1. {"workspaces":[{"id":"d4e26a01-xxxx-xxxx-xxxx-xxxxxxxxxxxx","name":"admin's Workspace","current":true}]}

    If there are multiple workspaces, select the one with current set to true, or choose the target workspace according to your business needs.

    Method 2: Query the Database Directly

    If you have database access, go to the deployment directory and connect to the built-in database:

    1. docker exec -it docker-db-1 psql -U postgres -d dify

    Then run the query:

    1. SELECT id, name FROM tenants;

    The UUID in the first column is the workspace ID. The second column helps confirm the workspace name.

    4. Final Checklist for the Three Configuration Items

    After completing the steps above, run a final check using the following checklist:

    1. Service address reachable: Use curl or a browser to access the base address directly and confirm that it returns a normal response.
    2. Key usable: Send a simple request with the configured key and verify that it returns status code 200 instead of 401.
    3. Workspace ID correct: Verify that the UUID belongs to the target workspace.
    4. Network isolation check: If the service is deployed in a container network, confirm that host-to-container port mapping is correct to avoid cross-network access failures.

    5. Additional Security Recommendations

    Automation improves efficiency, but poor key management introduces security risks. Recommended practices:

    • Do not hard-code administrator keys in script repositories. Inject them through environment variables or a secrets management service.
    • Assign separate keys to different automation tasks for easier auditing and revocation.
    • Enable HTTPS in production environments and apply access controls to API endpoints.
    • Rotate keys regularly, and replace them immediately after personnel changes or suspected leakage.

    Conclusion

    From confirming the address and enabling the key to locating the workspace, these three items form the entry ticket for automated management of an LLM application platform. Understanding the mechanism behind each setting—when environment variables are loaded, the difference between container recreation and restart, and the relationship between the tenant model and workspaces—not only solves current deployment issues but also lays a solid foundation for future operations troubleshooting. Once configuration is complete, scripts can replace manual work for batch application creation, version updates, and continuous deployment, letting you focus on the application logic itself.