{"record":{"id":"e9e7b0a7d25c60a0","repo":"microsoft/semantic-kernel","slug":"failed-to-create-openai-settings-e9e7b0","errorCode":null,"errorMessage":"Failed to create OpenAI settings.","messagePattern":"Failed to create OpenAI settings\\.","errorType":"exception","errorClass":"ServiceInitializationError","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/connectors/ai/open_ai/services/open_ai_audio_to_text.py","lineNumber":58,"sourceCode":"            org_id: The optional org ID to use. If provided will override,\n                the env vars or .env file value.\n            default_headers: The default headers mapping of string keys to\n                string values for HTTP requests. (Optional)\n            async_client: An existing client to use. (Optional)\n            env_file_path: Use the environment settings file as\n                a fallback to environment variables. (Optional)\n            env_file_encoding: The encoding of the environment settings file. (Optional)\n        \"\"\"\n        try:\n            openai_settings = OpenAISettings(\n                api_key=api_key,\n                org_id=org_id,\n                audio_to_text_model_id=ai_model_id,\n                env_file_path=env_file_path,\n                env_file_encoding=env_file_encoding,\n            )\n        except ValidationError as ex:\n            raise ServiceInitializationError(\"Failed to create OpenAI settings.\", ex) from ex\n        if not openai_settings.audio_to_text_model_id:\n            raise ServiceInitializationError(\"The OpenAI audio to text model ID is required.\")\n        super().__init__(\n            ai_model_id=openai_settings.audio_to_text_model_id,\n            api_key=openai_settings.api_key.get_secret_value() if openai_settings.api_key else None,\n            ai_model_type=OpenAIModelTypes.AUDIO_TO_TEXT,\n            org_id=openai_settings.org_id,\n            service_id=service_id,\n            default_headers=default_headers,\n            client=async_client,\n        )\n\n    @classmethod\n    def from_dict(cls: type[T_], settings: dict[str, Any]) -> T_:\n        \"\"\"Initialize an Open AI service from a dictionary of settings.\n\n        Args:\n            settings: A dictionary of settings for the service.","sourceCodeStart":40,"sourceCodeEnd":76,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/connectors/ai/open_ai/services/open_ai_audio_to_text.py#L40-L76","documentation":"Raised by OpenAIAudioToText.__init__ when OpenAISettings construction throws a pydantic ValidationError. The non-Azure OpenAISettings model has fewer fields than its Azure counterpart: api_key (SecretStr|None), org_id (str|None), audio_to_text_model_id (str|None). If a field value fails type coercion (e.g. api_key passed as bytes or org_id as a non-string), pydantic raises ValidationError which is wrapped here.","triggerScenarios":"Constructing OpenAIAudioToText with a malformed .env file, an api_key of the wrong type (e.g. bytes instead of str), or an environment variable with an incompatible value type. Since most fields are str|None, type errors are rare but can occur with corrupt env files.","commonSituations":"Corrupted .env file with invalid syntax; OPENAI_API_KEY env var set to an empty string in CI; env_file_encoding mismatch causing decode errors; passing api_key as a SecretStr object instead of a plain string.","solutions":["Inspect the chained ValidationError for the specific field and constraint that failed.","Pass api_key as a plain string (str), not a SecretStr or bytes.","Verify your .env file syntax and encoding (default is utf-8).","Ensure OPENAI_API_KEY is set to a non-empty string in the environment."],"exampleFix":"# before (passing SecretStr instead of str)\nfrom pydantic import SecretStr\nservice = OpenAIAudioToText(\n    ai_model_id='whisper-1',\n    api_key=SecretStr('sk-...'),  # wrong type\n)\n# after (plain string)\nservice = OpenAIAudioToText(\n    ai_model_id='whisper-1',\n    api_key='sk-...',\n)","handlingStrategy":"try-catch","validationCode":"import os\n\napi_key = os.environ.get('OPENAI_API_KEY')\nif not api_key or not isinstance(api_key, str):\n    raise ValueError(\n        'OPENAI_API_KEY must be set to a non-empty string in the environment or .env file.'\n    )","typeGuard":null,"tryCatchPattern":"from semantic_kernel.exceptions.service_exceptions import ServiceInitializationError\n\ntry:\n    service = OpenAIAudioToText(\n        ai_model_id='whisper-1',\n        api_key=os.environ.get('OPENAI_API_KEY'),\n    )\nexcept ServiceInitializationError as e:\n    cause = e.__cause__\n    if cause:\n        print(f'Settings validation failed: {cause}')\n    raise","preventionTips":["Pass api_key as a plain string, not a SecretStr or bytes.","Verify your .env file syntax and encoding (default utf-8).","Read the chained ValidationError (__cause__) for the specific field that failed.","Ensure OPENAI_API_KEY is a non-empty string in the environment."],"tags":["openai","audio-to-text","pydantic","settings-validation"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}