    async def add_service(self, spec: dict) -> Service:
        """Add a new service and related objects to the database

        Args:
            spec (dict): The service specification

        Raises:
            web.HTTPError: Raise if the service is not created

        Returns:
            Service: Returns the service instance.

        """

        self._check_service_model(spec)
        self._check_service_scopes(spec)

        service_name = spec["name"]
        managed = bool(spec.get('command'))
        if managed:
            msg = f"Can not create managed service {service_name} at runtime"
            self.log.error(msg, exc_info=True)
            raise web.HTTPError(400, msg)
        try:
            new_service = self.service_from_spec(spec)
        except Exception:
            msg = f"Failed to create service {service_name}"
            self.log.error(msg, exc_info=True)
            raise web.HTTPError(400, msg)

        if new_service is None:
            raise web.HTTPError(400, f"Failed to create service {service_name}")

        if new_service.api_token:
            # Add api token to database
            await self.app._add_tokens(
                {new_service.api_token: new_service.name}, kind='service'
            )
        if new_service.url:
            # Start polling for external service
            service_status = await self.app.start_service(service_name, new_service)
            if not service_status:
                self.log.error(
                    'Failed to start service %s',
                    service_name,
                    exc_info=True,
                )

        if new_service.oauth_no_confirm:
            oauth_no_confirm_list = self.settings.get('oauth_no_confirm_list')
            msg = f"Allowing service {new_service.name} to complete OAuth without confirmation on an authorization web page"
            self.log.warning(msg)
            oauth_no_confirm_list.add(new_service.oauth_client_id)

        return new_service
Add a new service and related objects to the database

Args:
spec (dict): The service specification

Raises:
web.HTTPError: Raise if the service is not created

Returns:
Service: Returns the service instance.
jupyterhub/apihandlers/services.py