LobbyService (401) HTTP/1.1 401 Unauthorized on Multiplay Dedicated Server

Hi there, I keep getting a

“Unity.Services.Lobbies.LobbyServiceException: (401) HTTP/1.1 401 Unauthorized”

when trying to call LobbyService.Instance.CreateLobbyAsync on a Multiplay Dedicated Server. I’ve tried authenticating with both ServerAuthenticationService.Instance.SignInWithServiceAccountAsync and ServerAuthenticationService.Instance.SignInFromServerAsync. Same result. I’ve checked ServerAuthenticationService.Instance.IsAuthorized, which returned true in both case. I’ve cleared my access policies “statements”: . I could not find any Lobby-related role for the Service Account to be assigned. What am I missing?

ServerConfigLoader serverConfigLoader = new();
string apiKeyIdentifier = serverConfigLoader.GetConfigVariable("serviceAccountIdentifier");
string apiKeySecret = serverConfigLoader.GetConfigVariable("serviceAccountSecret");
Debug.Log("Is server authorized (startup before sign-in): " + ServerAuthenticationService.Instance.IsAuthorized);
await ServerAuthenticationService.Instance.SignInWithServiceAccountAsync(apiKeyIdentifier, apiKeySecret);
Debug.Log("Is server authorized (startup after sign-in): " + ServerAuthenticationService.Instance.IsAuthorized);
StartServer();

I checked in the log of the server, the variable retrieved correctly.

Is server authorized (startup before sign-in): False
Is server authorized (startup after sign-in): True

I checked again in the class that is calling CreateLobbyAsync and it’s still returning true. Is it possible to call CreateLobbyAsync from a Dedicated Server? Should it be done exclusively from the API alternatively using Session?

Thank you very much in advance for your help!

After more research and a long night, I concluded that it is not possible to create a Lobby using the SDK on a dedicated service. Reason why is that no HostId is not provided at the creation if a service account is used for the creation.

I came to that conclusion by trying to create a lobby with the CLI and the REST API. Both method returned the following error message:

Lobby creation failed: {
  code: 16000,
  detail: 'request failed validation',
  details: [
    {
      errorType: 'validation',
      message: "missing serviceId in 'service-id' header"
    }
  ],
  status: 400,
  title: 'Bad Request',
  type: 'http://unity3d/lobby/errors/validation-error'
}

After some trial and error, I found out that the service-id is actually the HostId

D:\Development\Unity\CLI>ugs lobby create lobby.json --service-id **DefaultHostId**
class Lobby {
  Id: wjckW79oe6QVHfFLYapAgH
  LobbyCode: 77JRDF
  Upid: ...
  EnvironmentId: ...
  Name: Test
  MaxPlayers: 4
  AvailableSlots: 4
  IsPrivate: False
  IsLocked: False
  HasPassword: False
  Players: System.Collections.Generic.List`1[Unity.Services.MpsLobby.LobbyApiV1.Generated.Model.Player]
  Data:
  HostId: **DefaultHostId**
  Created: 04.02.2025 00:51:32
  LastUpdated: 04.02.2025 00:51:32
  _Version: 1
}

It would be great to update the docs as follows:

  • Update the SDK docs to mention it’s not possible to run the create function (maybe others Lobby functions?) on a dedicated server.
  • Update the REST API Doc to specify that the service-id must be provided as a header to indicate who is the HostId
  • Perhaps update the error message and make it clearer that the HostID is missing in the header instead of service-id.