{"library":"google-ai-generativelanguage","code":"import os\nfrom google.ai import generativelanguage_v1beta as glm\n\n# Initialize the client. This client will attempt to ascertain credentials \n# from the environment, e.g., via Application Default Credentials (ADC).\n# For local development, consider `gcloud auth application-default login`.\n# For API Key-based authentication (e.g., from Google AI Studio), the `google-genai` \n# library (pip install google-genai) is generally recommended.\nclient = glm.GenerativeServiceClient()\n\nmodel_name = \"models/gemini-pro\"  # Or another supported model like \"models/text-bison-001\"\n\n# Prepare the content for generation\ncontent = glm.Content(\n    parts=[glm.Part(text=\"Write a short poem about a cat sitting by a window.\")]\n)\n\ntry:\n    # Make the generate content request\n    response = client.generate_content(model=model_name, contents=[content])\n\n    # Extract the generated text\n    if response.candidates:\n        print(response.candidates[0].content.parts[0].text)\n    else:\n        print(\"No content generated.\")\n\nexcept Exception as e:\n    print(f\"An error occurred: {e}\")\n    print(\"Ensure you have enabled the Generative Language API in your Google Cloud project and set up authentication.\")\n\n# It's good practice to explicitly close the client when done to release resources.\nclient.close()","lang":"python","description":"This quickstart demonstrates how to instantiate the `GenerativeServiceClient` and use it to generate text with the Gemini Pro model. It highlights the typical setup for authentication using Application Default Credentials (ADC), suitable for Google Cloud environments.","tag":null,"tag_description":null,"last_tested":"2026-04-24","results":[{"runtime":"python:3.10-alpine","exit_code":1},{"runtime":"python:3.10-slim","exit_code":1},{"runtime":"python:3.11-alpine","exit_code":1},{"runtime":"python:3.11-slim","exit_code":1},{"runtime":"python:3.12-alpine","exit_code":1},{"runtime":"python:3.12-slim","exit_code":1},{"runtime":"python:3.13-alpine","exit_code":1},{"runtime":"python:3.13-slim","exit_code":1},{"runtime":"python:3.9-alpine","exit_code":1},{"runtime":"python:3.9-slim","exit_code":1}]}