{"record":{"id":"78be72046b494202","repo":"microsoft/semantic-kernel","slug":"please-provide-an-endpoint-or-a-base-url","errorCode":null,"errorMessage":"Please provide an endpoint or a base_url","messagePattern":"Please provide an endpoint or a base_url","errorType":"exception","errorClass":"ServiceInitializationError","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/connectors/ai/open_ai/services/azure_config_base.py","lineNumber":90,"sourceCode":"        merged_headers = dict(copy(default_headers)) if default_headers else {}\n        if APP_INFO:\n            merged_headers.update(APP_INFO)\n            merged_headers = prepend_semantic_kernel_to_user_agent(merged_headers)\n\n        if not client:\n            # If the client is None, the api_key is none, the ad_token is none, and the ad_token_provider is none,\n            # then we will attempt to get the ad_token using the default endpoint specified in the Azure OpenAI\n            # settings.\n            if not api_key and not ad_token_provider and not ad_token and token_endpoint and credential:\n                ad_token = get_entra_auth_token(credential, token_endpoint)\n\n            if not api_key and not ad_token and not ad_token_provider and not credential:\n                raise ServiceInitializationError(\n                    \"Please provide either api_key, ad_token, ad_token_provider, credential or a client.\"\n                )\n\n            if not endpoint and not base_url:\n                raise ServiceInitializationError(\"Please provide an endpoint or a base_url\")\n\n            args: dict[str, Any] = {\n                \"default_headers\": merged_headers,\n            }\n            if api_version:\n                args[\"api_version\"] = api_version\n            if ad_token:\n                args[\"azure_ad_token\"] = ad_token\n            if ad_token_provider:\n                args[\"azure_ad_token_provider\"] = ad_token_provider\n            if api_key:\n                args[\"api_key\"] = api_key\n            if base_url:\n                args[\"base_url\"] = str(base_url)\n            if endpoint and not base_url:\n                args[\"azure_endpoint\"] = str(endpoint)\n            # TODO (eavanvalkenburg): Remove the check on model type when the package fixes: https://github.com/openai/openai-python/issues/2120\n            if deployment_name and ai_model_type != OpenAIModelTypes.REALTIME:","sourceCodeStart":72,"sourceCodeEnd":108,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/connectors/ai/open_ai/services/azure_config_base.py#L72-L108","documentation":"Raised by AzureOpenAIConfigBase.__init__ — the shared base class for every Azure OpenAI service (chat, text, embedding, audio, image, realtime). After confirming an auth credential exists, it checks that at least one routing target was provided: either endpoint (the Azure resource URL, e.g. https://<resource>.openai.azure.com) or base_url (the full path including /openai/deployments/...). Without one, the underlying openai AsyncAzureOpenAI client cannot determine where to send requests.","triggerScenarios":"Constructing any Azure service subclass (AzureChatCompletion, AzureTextEmbedding, AzureTextToAudio, AzureRealtimeWebRTC, etc.) without passing endpoint= or base_url=, without passing a pre-built async_client, AND without AZURE_OPENAI_ENDPOINT or AZURE_OPENAI_BASE_URL in the environment or .env file. The auth check at line 84 must have already passed, so a credential (api_key / ad_token / credential) was supplied but no target URL.","commonSituations":"Missing or misnamed .env file; AZURE_OPENAI_ prefix typo (e.g. AZURE_OPENAI_ENDPOINT spelled AZURE_OPENAI_END_POINT); CI/CD pipeline where secrets are injected under different variable names; copy-pasting sample code without setting environment variables; .env file not loaded because env_file_path points to the wrong location.","solutions":["Set the AZURE_OPENAI_ENDPOINT environment variable to your Azure resource URL (e.g. https://myresource.openai.azure.com) or add AZURE_OPENAI_BASE_URL for the full deployment path.","Pass endpoint= explicitly in the constructor call: AzureChatCompletion(deployment_name='my-model', endpoint='https://myresource.openai.azure.com', api_key='...').","Ensure your .env file is discoverable — pass env_file_path='.env' or verify the working directory when the process starts.","If you have a pre-configured AsyncAzureOpenAI client, pass it via async_client= to bypass endpoint resolution entirely."],"exampleFix":"# before\nservice = AzureChatCompletion(\n    deployment_name='gpt-4o',\n    api_key=os.environ['AZURE_OPENAI_API_KEY'],\n)\n# after\nservice = AzureChatCompletion(\n    deployment_name='gpt-4o',\n    endpoint='https://myresource.openai.azure.com',\n    api_key=os.environ['AZURE_OPENAI_API_KEY'],\n)","handlingStrategy":"validation","validationCode":"import os\nfrom semantic_kernel.connectors.ai.open_ai.settings.azure_open_ai_settings import AzureOpenAISettings\n\n# Validate endpoint/base_url before constructing any Azure service\nsettings = AzureOpenAISettings.create()\nif not settings.endpoint and not settings.base_url:\n    raise ValueError(\n        \"AZURE_OPENAI_ENDPOINT or AZURE_OPENAI_BASE_URL must be set. \"\n        \"Found neither in environment or .env file.\"\n    )","typeGuard":null,"tryCatchPattern":"from semantic_kernel.exceptions.service_exceptions import ServiceInitializationError\n\ntry:\n    service = AzureChatCompletion(\n        deployment_name='gpt-4o',\n        endpoint='https://myresource.openai.azure.com',\n        api_key=os.environ['AZURE_OPENAI_API_KEY'],\n    )\nexcept ServiceInitializationError as e:\n    if 'endpoint or a base_url' in str(e):\n        # Configuration error — check env vars and .env file\n        print(f'Missing Azure endpoint config: {e}')\n    raise","preventionTips":["Always set AZURE_OPENAI_ENDPOINT in your .env file during development.","Use a settings validation helper at application startup to fail fast on missing config.","In CI/CD, inject secrets as environment variables and verify they are set before constructing services.","Consider passing a pre-built AsyncAzureOpenAI client to decouple client construction from service construction."],"tags":["azure-openai","configuration","endpoint","env-vars","service-initialization"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}