{"id":9292,"library":"sap-ai-sdk-gen","title":"SAP AI SDK for Generative AI","description":"The SAP Cloud SDK for AI (Python) is designed to simplify interactions with generative AI APIs and services, particularly within the SAP ecosystem. It provides unified interfaces for various large language models (LLMs), enabling developers to easily integrate AI capabilities into their applications. The library is currently at version 6.7.0 and maintains a regular release cadence with updates and new features.","status":"active","version":"6.7.0","language":"en","source_language":"en","source_url":"https://github.com/SAP/cloud-sdk-for-ai-python","tags":["SAP","AI","Generative AI","LLM","Cloud"],"install":[{"cmd":"pip install sap-ai-sdk-gen","lang":"bash","label":"Install core SDK"}],"dependencies":[],"imports":[{"symbol":"GenerativeAI","correct":"from sap_ai_sdk.generative_ai import GenerativeAI"},{"note":"The 'generative_ai' submodule was introduced in v6.x as part of a refactor.","wrong":"from sap_ai_sdk.completion import Completion","symbol":"Completion","correct":"from sap_ai_sdk.generative_ai.completion import Completion"},{"symbol":"Chat","correct":"from sap_ai_sdk.generative_ai.chat import Chat"},{"symbol":"ImageGeneration","correct":"from sap_ai_sdk.generative_ai.image_generation import ImageGeneration"}],"quickstart":{"code":"import os\nfrom sap_ai_sdk.generative_ai import GenerativeAI\nfrom sap_ai_sdk.generative_ai.completion import Completion\n\n# Set your API key as an environment variable (e.g., OPENAI_API_KEY).\n# For SAP AI Core, ensure AI_API_URL, AI_CLIENT_ID, AI_CLIENT_SECRET, AI_AUTH_URL are set.\n# Example: os.environ['OPENAI_API_KEY'] = os.environ.get('OPENAI_API_KEY', '') # For demo, ensure it's loaded.\n\ntry:\n    # Initialize the GenerativeAI client. It automatically detects configured providers.\n    ai_client = GenerativeAI()\n\n    # Get the completion service\n    completion_service: Completion = ai_client.get_completion_service()\n\n    prompt = \"Explain the concept of quantum entanglement in simple terms.\"\n    model_name = \"gpt-3.5-turbo\" # Use a model supported by your configured provider\n\n    print(f\"Requesting completion for model: {model_name}\")\n    response = completion_service.create(\n        prompt=prompt,\n        model_name=model_name,\n        # provider=\"openai\" # Optionally specify if multiple providers are configured\n    )\n\n    print(\"\\nGenerated Text:\")\n    print(response.text)\n\nexcept Exception as e:\n    print(f\"An error occurred: {e}\")\n    print(\"Please ensure your environment variables (e.g., OPENAI_API_KEY) are correctly set\")\n    print(\"and that a suitable provider is configured for the chosen model.\")","lang":"python","description":"This quickstart demonstrates how to initialize the `GenerativeAI` client and use its `Completion` service. It relies on environment variables for API key configuration (e.g., `OPENAI_API_KEY`) and attempts to generate text using a specified model."},"warnings":[{"fix":"Initialize `GenerativeAI` and then use methods like `ai_client.get_completion_service()` to obtain service instances.","message":"The SDK underwent significant refactoring in version 6.x. The `GenerativeAI` class is now the central entry point for all services (completion, chat, image generation, etc.). Direct instantiation of services like `Completion()` with a configuration object is no longer the recommended or supported pattern.","severity":"breaking","affected_versions":">=6.0.0"},{"fix":"Ensure relevant environment variables (e.g., `OPENAI_API_KEY`, `AI_API_URL`, `AI_CLIENT_ID`, `AI_CLIENT_SECRET`) are correctly set before initializing the `GenerativeAI` client. Refer to the documentation for provider-specific requirements.","message":"Authentication for generative AI providers (e.g., OpenAI, Azure OpenAI, SAP AI Core) relies heavily on environment variables or explicit `Credentials` objects. Misconfigured or missing API keys/credentials will lead to authentication errors (e.g., 401 Unauthorized).","severity":"gotcha","affected_versions":"all"},{"fix":"Always check which providers are configured and, if necessary, explicitly pass the `provider` name to the relevant methods.","message":"When using multiple configured providers or if auto-detection fails, explicitly specifying the `provider` parameter when getting a service (e.g., `ai_client.get_completion_service(provider=\"openai\")`) or in the service call (`completion_service.create(..., provider=\"openai\")`) can prevent `ProviderNotFoundException`.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Run `pip install sap-ai-sdk-gen` to install the library.","cause":"The `sap-ai-sdk-gen` library is not installed in your Python environment.","error":"ModuleNotFoundError: No module named 'sap_ai_sdk'"},{"fix":"Ensure that the necessary environment variables for your chosen provider (e.g., `OPENAI_API_KEY`, SAP AI Core variables) are correctly set, or explicitly pass the `provider` argument to the `GenerativeAI` client or service methods if multiple are configured.","cause":"The SDK could not find a configured provider or the specified provider name is incorrect/unconfigured.","error":"sap_ai_sdk.generative_ai.exceptions.ProviderNotFoundException: No provider found for [...]"},{"fix":"Ensure you are on the latest SDK version. Check that your API keys are correctly set. For `response_format`, ensure you are passing either `ResponseFormatType.JSON_OBJECT` or `ResponseFormatType.TEXT` (imported from `sap_ai_sdk.generative_ai.types`) as specified by the documentation for the `response_format` parameter, or omit it if not needed.","cause":"You are likely using an older version of the SDK or an unsupported configuration for the `response_format` in the `create` call. This error also often appears when API keys are missing, as the request object might not be fully formed or validated against the correct provider schema.","error":"pydantic.v1_pydantic_core.core_schema.ValidationError: 1 validation error for CompletionRequest\nresponse_format.type\n  value is not a valid enumeration member; permitted: 'text', 'json_object'"},{"fix":"Verify the `model_name` is correct and supported by your chosen provider (e.g., 'gpt-3.5-turbo', 'gpt-4o' for OpenAI). Refer to the provider's documentation for available models.","cause":"The specified `model_name` does not exist or is not available for the configured provider.","error":"sap_ai_sdk.generative_ai.exceptions.ModelNotFoundException: Model 'non-existent-model' not found for provider 'openai'"}]}