{"id":22063913,"url":"https://github.com/andrewyng/aisuite","last_synced_at":"2026-06-11T03:01:26.914Z","repository":{"id":265107376,"uuid":"822285449","full_name":"andrewyng/aisuite","owner":"andrewyng","description":"Simple, unified interface to multiple Generative AI providers ","archived":false,"fork":false,"pushed_at":"2026-06-08T20:34:18.000Z","size":1485,"stargazers_count":13806,"open_issues_count":129,"forks_count":1456,"subscribers_count":173,"default_branch":"main","last_synced_at":"2026-06-08T21:21:02.869Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/andrewyng.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2024-06-30T20:07:46.000Z","updated_at":"2026-06-08T20:34:24.000Z","dependencies_parsed_at":null,"dependency_job_id":"dcb5641b-e7b1-41c2-9956-b69adc873a19","html_url":"https://github.com/andrewyng/aisuite","commit_stats":null,"previous_names":["andrewyng/aisuite"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/andrewyng/aisuite","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrewyng%2Faisuite","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrewyng%2Faisuite/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrewyng%2Faisuite/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrewyng%2Faisuite/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/andrewyng","download_url":"https://codeload.github.com/andrewyng/aisuite/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrewyng%2Faisuite/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34180147,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-11T02:00:06.485Z","response_time":57,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-30T19:01:53.566Z","updated_at":"2026-06-11T03:01:26.905Z","avatar_url":"https://github.com/andrewyng.png","language":"Python","funding_links":[],"categories":["评估 Evaluation","Industry Strength Natural Language Processing","A01_文本生成_文本对话","Developer Tools \u0026 Infrastructure","Python","Repos","Other","5. Retrieval-Augmented Generation (RAG) \u0026 Knowledge","2. Libraries \u0026 Frameworks","🤖 AI \u0026 Machine Learning"],"sub_categories":["大语言对话模型及数据","Python"],"readme":"#  aisuite\n\n[![PyPI](https://img.shields.io/pypi/v/aisuite)](https://pypi.org/project/aisuite/)\n[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)\n\n`aisuite` is a lightweight Python library that provides a **unified API for working with multiple Generative AI providers**.  \nIt offers a consistent interface for models from *OpenAI, Anthropic, Google, Hugging Face, AWS, Cohere, Mistral, Ollama, OpenRouter*, and others—abstracting away SDK differences, authentication details, and parameter variations.  \nIts design is modeled after OpenAI’s API style, making it instantly familiar and easy to adopt.\n\n`aisuite` lets developers build and **run LLM-based or agentic applications across providers** with minimal setup.  \nWhile it’s not a full-blown agents framework, it includes simple abstractions for creating standalone, lightweight agents.  \nIt’s designed for low learning curve — so you can focus on building AI systems, not integrating APIs.\n\n---\n\n## Key Features\n\n`aisuite` is designed to eliminate the complexity of working with multiple LLM providers while keeping your code simple and portable. Whether you're building a chatbot, an agentic application, or experimenting with different models, `aisuite` provides the abstractions you need without getting in your way.\n\n* **Unified API for multiple model providers** – Write your code once and run it with any supported provider. Switch between OpenAI, Anthropic, Google, and others with a single parameter change.\n* **Easy agentic app or agent creation** – Build multi-turn agentic applications using a single parameter `max_turns`. No need to manually manage tool execution loops.\n* **Pass Tool calls easily** – Pass real Python functions instead of JSON specs; aisuite handles schema generation and execution automatically.\n* **MCP tools** – Connect to MCP-based tools without writing boilerplate; aisuite handles connection, schema and execution seamlessly.\n* **Modular and extensible provider architecture** – Add support for new providers with minimal code. The plugin-style architecture makes extensions straightforward.\n\n---\n\n## Installation\n\nYou can install just the base `aisuite` package, or install a provider's package along with `aisuite`.\n\nInstall just the base package without any provider SDKs:\n\n```shell\npip install aisuite\n```\n\nInstall aisuite with a specific provider (e.g., Anthropic):\n\n```shell\npip install 'aisuite[anthropic]'\n```\n\nInstall aisuite with all provider libraries:\n\n```shell\npip install 'aisuite[all]'\n```\n\n## Setup\n\nTo get started, you will need API Keys for the providers you intend to use. You'll need to\ninstall the provider-specific library either separately or when installing aisuite.\n\nThe API Keys can be set as environment variables, or can be passed as config to the aisuite Client constructor.\nYou can use tools like [`python-dotenv`](https://pypi.org/project/python-dotenv/) or [`direnv`](https://direnv.net/) to set the environment variables manually. Please take a look at the `examples` folder to see usage.\n\nHere is a short example of using `aisuite` to generate chat completion responses from gpt-4o and claude-3-5-sonnet.\n\nSet the API keys.\n\n```shell\nexport OPENAI_API_KEY=\"your-openai-api-key\"\nexport ANTHROPIC_API_KEY=\"your-anthropic-api-key\"\nexport OPENROUTER_API_KEY=\"your-openrouter-api-key\"\n```\n\nUse the python client.\n\n```python\nimport aisuite as ai\nclient = ai.Client()\n\nmodels = [\"openai:gpt-4o\", \"anthropic:claude-3-5-sonnet-20240620\",\"openrouter:google/gemma-4-26b-a4b-it:free\"]\n\nmessages = [\n    {\"role\": \"system\", \"content\": \"Respond in Pirate English.\"},\n    {\"role\": \"user\", \"content\": \"Tell me a joke.\"},\n]\n\nfor model in models:\n    response = client.chat.completions.create(\n        model=model,\n        messages=messages,\n        temperature=0.75\n    )\n    print(response.choices[0].message.content)\n\n```\n\nNote that the model name in the create() call uses the format - `\u003cprovider\u003e:\u003cmodel-name\u003e`.\n`aisuite` will call the appropriate provider with the right parameters based on the provider value.\nFor a list of provider values, you can look at the directory - `aisuite/providers/`. The list of supported providers are of the format - `\u003cprovider\u003e_provider.py` in that directory. We welcome providers to add support to this library by adding an implementation file in this directory. Please see section below for how to contribute.\n\nFor more examples, check out the `examples` directory where you will find several notebooks that you can run to experiment with the interface.\n\n---\n\n## Chat Completions\n\nThe chat API provides a high-level abstraction for model interactions. It supports all core parameters (`temperature`, `max_tokens`, `tools`, etc.) in a provider-agnostic way.\n\n```python\nresponse = client.chat.completions.create(\n    model=\"google:gemini-pro\",\n    messages=[{\"role\": \"user\", \"content\": \"Summarize this paragraph.\"}],\n)\nprint(response.choices[0].message.content)\n```\n\n`aisuite` standardizes request and response structures so you can focus on logic rather than SDK differences.\n\n---\n\n## Tool Calling \u0026 Agentic apps\n\n`aisuite` provides a simple abstraction for tool/function calling that works across supported providers. This is in addition to the regular abstraction of passing JSON spec of the tool to the `tools` parameter. The tool calling abstraction makes it easy to use tools with different LLMs without changing your code.\n\nThere are two ways to use tools with `aisuite`:\n\n### 1. Manual Tool Handling\n\nThis is the default behavior when `max_turns` is not specified. In this mode, you have full control over the tool execution flow. You pass tools using the standard OpenAI JSON schema format, and `aisuite` returns the LLM's tool call requests in the response. You're then responsible for executing the tools, processing results, and sending them back to the model in subsequent requests.\n\nThis approach is useful when you need:\n- Fine-grained control over tool execution logic\n- Custom error handling or validation before executing tools\n- The ability to selectively execute or skip certain tool calls\n- Integration with existing tool execution pipelines\n\nYou can pass tools in the OpenAI tool format:\n\n```python\ndef will_it_rain(location: str, time_of_day: str):\n    \"\"\"Check if it will rain in a location at a given time today.\n    \n    Args:\n        location (str): Name of the city\n        time_of_day (str): Time of the day in HH:MM format.\n    \"\"\"\n    return \"YES\"\n\ntools = [{\n    \"type\": \"function\",\n    \"function\": {\n        \"name\": \"will_it_rain\",\n        \"description\": \"Check if it will rain in a location at a given time today\",\n        \"parameters\": {\n            \"type\": \"object\",\n            \"properties\": {\n                \"location\": {\n                    \"type\": \"string\",\n                    \"description\": \"Name of the city\"\n                },\n                \"time_of_day\": {\n                    \"type\": \"string\",\n                    \"description\": \"Time of the day in HH:MM format.\"\n                }\n            },\n            \"required\": [\"location\", \"time_of_day\"]\n        }\n    }\n}]\n\nresponse = client.chat.completions.create(\n    model=\"openai:gpt-4o\",\n    messages=messages,\n    tools=tools\n)\n```\n\n### 2. Automatic Tool Execution\n\nWhen `max_turns` is specified, you can pass a list of callable Python functions as the `tools` parameter. `aisuite` will automatically handle the tool calling flow:\n\n```python\ndef will_it_rain(location: str, time_of_day: str):\n    \"\"\"Check if it will rain in a location at a given time today.\n    \n    Args:\n        location (str): Name of the city\n        time_of_day (str): Time of the day in HH:MM format.\n    \"\"\"\n    return \"YES\"\n\nclient = ai.Client()\nmessages = [{\n    \"role\": \"user\",\n    \"content\": \"I live in San Francisco. Can you check for weather \"\n               \"and plan an outdoor picnic for me at 2pm?\"\n}]\n\n# Automatic tool execution with max_turns\nresponse = client.chat.completions.create(\n    model=\"openai:gpt-4o\",\n    messages=messages,\n    tools=[will_it_rain],\n    max_turns=2  # Maximum number of back-and-forth tool calls\n)\nprint(response.choices[0].message.content)\n```\n\nWhen `max_turns` is specified, `aisuite` will:\n1. Send your message to the LLM\n2. Execute any tool calls the LLM requests\n3. Send the tool results back to the LLM\n4. Repeat until the conversation is complete or max_turns is reached\n\nIn addition to `response.choices[0].message`, there is an additional field `response.choices[0].intermediate_messages` which contains the list of all messages including tool interactions used. This can be used to continue the conversation with the model.\nFor more detailed examples of tool calling, check out the `examples/tool_calling_abstraction.ipynb` notebook.\n\n### Model Context Protocol (MCP) Integration\n\n`aisuite` natively supports **MCP**, a standard protocol that allows LLMs to securely call external tools and access data. You can connect to MCP servers—such as a filesystem or database—and expose their tools directly to your model.\nRead more about MCP here - https://modelcontextprotocol.io/docs/getting-started/intro\n\nInstall aisuite with MCP support:\n\n```shell\npip install 'aisuite[mcp]'\n```\n\nYou'll also need an MCP server. For example, to use the filesystem server:\n\n```shell\nnpm install -g @modelcontextprotocol/server-filesystem\n```\n\nThere are two ways to use MCP tools with aisuite:\n\n#### Option 1: Config Dict Format (Recommended for Simple Use Cases)\n\n```python\nimport aisuite as ai\n\nclient = ai.Client()\nresponse = client.chat.completions.create(\n    model=\"openai:gpt-4o\",\n    messages=[{\"role\": \"user\", \"content\": \"List the files in the current directory\"}],\n    tools=[{\n        \"type\": \"mcp\",\n        \"name\": \"filesystem\",\n        \"command\": \"npx\",\n        \"args\": [\"-y\", \"@modelcontextprotocol/server-filesystem\", \"/path/to/directory\"]\n    }],\n    max_turns=3\n)\n\nprint(response.choices[0].message.content)\n```\n\n#### Option 2: Explicit MCPClient (Recommended for Advanced Use Cases)\n\n```python\nimport aisuite as ai\nfrom aisuite.mcp import MCPClient\n\n# Create MCP client once, reuse across requests\nmcp = MCPClient(\n    command=\"npx\",\n    args=[\"-y\", \"@modelcontextprotocol/server-filesystem\", \"/path/to/directory\"]\n)\n\n# Use with aisuite\nclient = ai.Client()\nresponse = client.chat.completions.create(\n    model=\"openai:gpt-4o\",\n    messages=[{\"role\": \"user\", \"content\": \"List the files\"}],\n    tools=mcp.get_callable_tools(),\n    max_turns=3\n)\n\nprint(response.choices[0].message.content)\nmcp.close()  # Clean up\n```\n\nFor detailed usage (security filters, tool prefixing, and `MCPClient` management), see [docs/mcp-tools.md](docs/mcp-tools.md).\nFor detailed examples, see `examples/mcp_tools_example.ipynb`.\n\n---\n\n## Extending aisuite: Adding a Provider\n\nNew providers can be added by implementing a lightweight adapter. The system uses a naming convention for discovery:\n\n| Element         | Convention                         |\n| --------------- | ---------------------------------- |\n| **Module file** | `\u003cprovider\u003e_provider.py`           |\n| **Class name**  | `\u003cProvider\u003eProvider` (capitalized) |\n\nExample:\n\n```python\n# providers/openai_provider.py\nclass OpenaiProvider(BaseProvider):\n    ...\n```\n\nThis convention ensures consistency and enables automatic loading of new integrations.\n\n---\n\n## Contributing\n\nContributions are welcome. Please review the [Contributing Guide](https://github.com/andrewyng/aisuite/blob/main/CONTRIBUTING.md) and join our [Discord](https://discord.gg/T6Nvn8ExSb) for discussions.\n\n---\n\n## License\n\nReleased under the **MIT License** — free for commercial and non-commercial use.\n\n---\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandrewyng%2Faisuite","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fandrewyng%2Faisuite","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandrewyng%2Faisuite/lists"}