{"record":{"id":"3f66913c6e1782a7","repo":"microsoft/semantic-kernel","slug":"a-valid-model-id-or-endpoint-must-be-provided","errorCode":null,"errorMessage":"A valid model id or endpoint must be provided.","messagePattern":"A valid model id or endpoint must be provided\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"dotnet/src/Connectors/Connectors.HuggingFace/Core/HuggingFaceClient.cs","lineNumber":44,"sourceCode":"    internal string? ModelId { get; }\n    internal string? ApiKey { get; }\n    internal Uri Endpoint { get; }\n    internal string Separator { get; }\n    internal ILogger Logger { get; }\n\n    internal HuggingFaceClient(\n        HttpClient httpClient,\n        string? modelId = null,\n        Uri? endpoint = null,\n        string? apiKey = null,\n        ILogger? logger = null)\n    {\n        Verify.NotNull(httpClient);\n\n        endpoint ??= httpClient.BaseAddress;\n        if (string.IsNullOrWhiteSpace(modelId) && endpoint is null)\n        {\n            throw new InvalidOperationException(\"A valid model id or endpoint must be provided.\");\n        }\n\n        endpoint ??= new Uri(\"https://api-inference.huggingface.co\");\n        this.Separator = endpoint.AbsolutePath.EndsWith(\"/\", StringComparison.InvariantCulture) ? string.Empty : \"/\";\n        this.Endpoint = endpoint;\n        this.ModelId = modelId;\n        this.ApiKey = apiKey;\n        this._httpClient = httpClient;\n        this.Logger = logger ?? NullLogger.Instance;\n    }\n\n    #region ClientCore\n    internal static void ValidateMaxTokens(int? maxTokens)\n    {\n        if (maxTokens is < 1)\n        {\n            throw new ArgumentException($\"MaxTokens {maxTokens} is not valid, the value must be greater than zero\");\n        }","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/dotnet/src/Connectors/Connectors.HuggingFace/Core/HuggingFaceClient.cs#L26-L62","documentation":"Thrown by the HuggingFaceClient constructor when both modelId is null/whitespace and no endpoint is available (the endpoint parameter is null and httpClient.BaseAddress is also null). The client needs at least one to know where to send requests.","triggerScenarios":"Constructing HuggingFaceTextGeneration / HuggingFaceChatCompletion / image services with a modelId of null AND an HttpClient that has no BaseAddress AND no explicit endpoint, then trying to build the client.","commonSituations":"Forgetting to pass a model id when using a bare HttpClient without a base address; misconfiguring DI registration where modelId is read from a null config key; using a custom HttpClient that was created without BaseAddress.","solutions":["Supply a non-empty modelId when constructing the HuggingFace service.","Or set HttpClient.BaseAddress to the HuggingFace inference endpoint.","Or pass an explicit endpoint Uri to the constructor."],"exampleFix":"// before\nvar http = new HttpClient();  // no BaseAddress\nvar svc = new HuggingFaceTextGenerationService(modelId: null, httpClient: http);  // throws\n\n// after\nvar svc = new HuggingFaceTextGenerationService(modelId: \"gpt2\", httpClient: http);","handlingStrategy":"validation","validationCode":"static void EnsureHfConfig(string? modelId, Uri? endpoint, HttpClient http)\n{\n    endpoint ??= http.BaseAddress;\n    if (string.IsNullOrWhiteSpace(modelId) && endpoint is null)\n        throw new InvalidOperationException(\"Provide a HuggingFace modelId or endpoint.\");\n}","typeGuard":"static bool HasHfTarget(string? modelId, Uri? endpoint, HttpClient http)\n    => !string.IsNullOrWhiteSpace(modelId) || endpoint is not null || http.BaseAddress is not null;","tryCatchPattern":null,"preventionTips":["Always pass a modelId when constructing HuggingFace services.","Or set HttpClient.BaseAddress / pass an endpoint.","Validate DI configuration keys are non-null at startup."],"tags":["huggingface","configuration","endpoint","validation"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}