{"id":9468,"library":"any-llm-sdk","title":"Any-LLM SDK","description":"The Any-LLM SDK provides a unified Python interface for interacting with various Large Language Model (LLM) providers through the Any-LLM gateway. It aims to abstract away provider-specific complexities, offering a consistent API for chat completions, embeddings, and more. The current version is 1.13.0, and it maintains a rapid release cadence with frequent updates and improvements.","status":"active","version":"1.13.0","language":"en","source_language":"en","source_url":"https://github.com/mozilla-ai/any-llm","tags":["LLM","AI","API Client","Multi-provider","Mozilla","Gateway"],"install":[{"cmd":"pip install any-llm-sdk","lang":"bash","label":"Install core SDK"}],"dependencies":[{"reason":"Required for core functionality and API type compatibility.","package":"openai","optional":false},{"reason":"Required for core functionality and API type compatibility, as of v1.13.0.","package":"anthropic","optional":false}],"imports":[{"symbol":"Gateway","correct":"from any_llm_sdk import Gateway"},{"note":"Message types are re-exported via 'any_llm_sdk.types.messages' and often directly from 'anthropic.types'.","wrong":"from any_llm_sdk.messages import Message","symbol":"messages","correct":"from any_llm_sdk.types import messages"}],"quickstart":{"code":"import os\nfrom any_llm_sdk import Gateway\nfrom any_llm_sdk.types import messages\n\n# Ensure these environment variables are set:\n# os.environ['ANY_LLM_GATEWAY_URL'] = 'YOUR_GATEWAY_URL'\n# os.environ['ANY_LLM_GATEWAY_API_KEY'] = 'YOUR_API_KEY'\n\ntry:\n    gateway = Gateway(\n        base_url=os.environ.get('ANY_LLM_GATEWAY_URL', 'https://gateway.any-llm.ai'),\n        api_key=os.environ.get('ANY_LLM_GATEWAY_API_KEY', '')\n    )\n\n    messages_payload = [\n        messages.UserMessage(content='Hello, what is the capital of France?')\n    ]\n\n    chat_completion = gateway.chat.completions.create(\n        model='gpt-4o',\n        messages=messages_payload,\n        max_tokens=100\n    )\n    print(chat_completion.choices[0].message.content)\n\nexcept Exception as e:\n    print(f\"An error occurred: {e}\")\n    print(\"Please ensure ANY_LLM_GATEWAY_URL and ANY_LLM_GATEWAY_API_KEY environment variables are set.\")","lang":"python","description":"Initializes the Any-LLM Gateway client using environment variables for the gateway URL and API key, then sends a simple chat completion request to a specified model. The `messages` types from `any_llm_sdk.types` (re-exporting Anthropic types) are used for constructing the payload."},"warnings":[{"fix":"Ensure `anthropic` is compatible with your environment or explicitly install `pip install any-llm-sdk anthropic`.","message":"As of v1.13.0, the `anthropic` SDK is now a required dependency, similar to `openai`. Users upgrading or installing might encounter new dependency conflicts if they weren't explicitly managing `anthropic` before.","severity":"breaking","affected_versions":">=1.13.0"},{"fix":"Review Anthropic provider calls and explicitly add the 'thinking_budget' parameter if you were relying on the default behavior for older models.","message":"For Anthropic provider users, v1.9.0 introduced a breaking change regarding adaptive thinking. Older models now require manual specification of the 'thinking budget' parameter, which is no longer set by default.","severity":"breaking","affected_versions":">=1.9.0"},{"fix":"Always set `ANY_LLM_GATEWAY_URL` and `ANY_LLM_GATEWAY_API_KEY` in your environment before running applications that use the SDK.","message":"The SDK relies on `ANY_LLM_GATEWAY_URL` and `ANY_LLM_GATEWAY_API_KEY` environment variables. If these are not set, the `Gateway` client will fail to initialize or authenticate, leading to `ConfigurationError` or `AuthenticationError`.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Verify that the model name you are using (`model='...'`) is correctly configured and available through your Any-LLM Gateway instance.","message":"While the SDK abstracts providers, specific models (e.g., 'gpt-4o', 'claude-3-opus-20240229') must be available via your configured Any-LLM Gateway. Using a non-existent or unsupported model will result in an API error.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-17T00:00:00.000Z","next_check":"2026-07-16T00:00:00.000Z","problems":[{"fix":"Run: `pip install any-llm-sdk`","cause":"The `any-llm-sdk` package is not installed in your Python environment.","error":"ModuleNotFoundError: No module named 'any_llm_sdk'"},{"fix":"Set the `ANY_LLM_GATEWAY_API_KEY` environment variable to your valid API key. Example: `export ANY_LLM_GATEWAY_API_KEY='your_api_key_here'`.","cause":"The `ANY_LLM_GATEWAY_API_KEY` environment variable is not set or contains an invalid key, preventing authentication with the Any-LLM gateway.","error":"any_llm_sdk.exceptions.AuthenticationError: Missing API key or invalid credentials."},{"fix":"Set the `ANY_LLM_GATEWAY_URL` environment variable to your Any-LLM Gateway endpoint. Example: `export ANY_LLM_GATEWAY_URL='https://gateway.any-llm.ai'`.","cause":"The `ANY_LLM_GATEWAY_URL` environment variable is not set, preventing the SDK from knowing which gateway to connect to.","error":"any_llm_sdk.exceptions.ConfigurationError: Missing gateway URL. Set ANY_LLM_GATEWAY_URL environment variable."},{"fix":"The `Gateway` class is a top-level import. Use `from any_llm_sdk import Gateway`.","cause":"You are trying to import `Gateway` from an incorrect sub-module path.","error":"ImportError: cannot import name 'Gateway' from 'any_llm_sdk.client' (or similar subpath)"}]}