{"id":4416,"library":"aistudio-sdk","title":"AIStudio Python SDK","description":"The `aistudio-sdk` is a Python client library for interacting with the AIStudio API. It provides convenient access to AI models for tasks like text generation. Currently at version 0.3.8, it receives frequent updates aligning with the underlying API's evolution.","status":"active","version":"0.3.8","language":"en","source_language":"en","source_url":"https://github.com/aistudio-team/aistudio-sdk","tags":["AI","ML","API client","Generative AI","Text Generation"],"install":[{"cmd":"pip install aistudio-sdk","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Asynchronous I/O support","package":"anyio"},{"reason":"HTTP client for API requests","package":"httpx"},{"reason":"Configuration and data handling","package":"pyyaml"},{"reason":"Progress bar for long operations (optional user-facing feature)","package":"tqdm"},{"reason":"Backports and extensions for typing features","package":"typing_extensions"}],"imports":[{"symbol":"TextGeneration","correct":"from aistudio import TextGeneration"},{"note":"The primary `Client` class is exposed at the top-level `aistudio` package.","wrong":"from aistudio.client import Client","symbol":"Client","correct":"from aistudio import Client"}],"quickstart":{"code":"import os\nfrom aistudio import TextGeneration\n\n# Ensure the AISTUDIO_API_KEY environment variable is set.\n# Example: export AISTUDIO_API_KEY=\"your_secret_key\"\n# For local testing without setting a real key (will likely fail API calls):\n# os.environ['AISTUDIO_API_KEY'] = 'sk-aistudio-dummy-key'\n\ntry:\n    # The SDK automatically picks up AISTUDIO_API_KEY from environment variables.\n    gen = TextGeneration()\n    response = gen.create(\n        prompt=\"Hello, my name is\",\n        model=\"gpt-3.5-turbo\", # Replace with an available model on AIStudio\n        temperature=0.7,\n        max_tokens=20\n    )\n    print(\"Generated text:\", response.text)\nexcept Exception as e:\n    print(f\"An error occurred: {e}\")\n    print(\"Please ensure AISTUDIO_API_KEY is set and valid, and the model specified is available.\")\n","lang":"python","description":"This quickstart demonstrates how to perform text generation using the `TextGeneration` class. The SDK automatically picks up the `AISTUDIO_API_KEY` from environment variables. Remember to replace 'gpt-3.5-turbo' with an actual model supported by the AIStudio API."},"warnings":[{"fix":"Always review release notes for `aistudio-sdk` when upgrading. Pin your dependency to a specific minor version (e.g., `aistudio-sdk~=0.3.0`) in production to control updates.","message":"As the library is in its 0.x.x version, breaking changes to the API surface (class names, method signatures, return types) may occur in minor releases without a full major version bump.","severity":"breaking","affected_versions":"0.x.x (all versions before 1.0.0)"},{"fix":"Ensure `AISTUDIO_API_KEY` is consistently set in your environment. If you need to manage multiple keys or explicitly pass one, instantiate `aistudio.Client(api_key=\"...\")` first and then pass that client to service classes if they support it, or set the environment variable programmatically with `os.environ['AISTUDIO_API_KEY'] = '...'` before initializing the service.","message":"The SDK primarily relies on the `AISTUDIO_API_KEY` environment variable for authentication. While a `Client` object can be instantiated with an `api_key` argument, service classes like `TextGeneration` do not directly accept `api_key` in their constructor.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Consult the official AIStudio API documentation or SDK methods (if available) to get a list of currently supported models before making API calls.","message":"The example models provided in the documentation (e.g., 'gpt-3.5-turbo') are illustrative. The actual availability and names of models depend on the AIStudio API itself and may change. Using an unsupported model will result in an API error.","severity":"gotcha","affected_versions":"All versions"},{"fix":"When an API call fails, inspect the full exception object or response object for `status_code`, `error` fields, or other diagnostic information to understand the cause (e.g., rate limits, invalid input, authentication issues).","message":"API responses may contain detailed error messages or specific structures beyond just `response.text` for generation results. Ignoring these can lead to missed debugging opportunities.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-12T00:00:00.000Z","next_check":"2026-07-11T00:00:00.000Z"}