One consistent function to call any LLM provider — Anthropic, OpenAI, Gemini, Moonshot, and more.
Project description
polygate
One function. Any LLM provider.
polygate is a tiny, dependency-light wrapper that gives you a single
consistent interface for calling Anthropic (Claude), OpenAI, Google
Gemini, and Moonshot (Kimi K2) — instead of learning four different
SDKs and four different response shapes.
from polygate import chat
response = chat(
provider="anthropic", # or "openai", "gemini", "moonshot"
model="claude-sonnet-4-6",
messages=[{"role": "user", "content": "Say hi in one word."}],
api_key="sk-...", # or set ANTHROPIC_API_KEY in the environment
)
print(response.content) # "Hi!"
print(response.usage) # Usage(prompt_tokens=..., completion_tokens=..., total_tokens=...)
import { chat } from "polygate";
const response = await chat({
provider: "openai",
model: "gpt-4o",
messages: [{ role: "user", content: "Say hi in one word." }],
apiKey: "sk-...", // or set OPENAI_API_KEY in the environment
});
console.log(response.content);
This repo isn't trying to out-feature mature gateways like LiteLLM, Portkey, or Helicone — it's a small, boring, easy-to-read wrapper built to be genuinely simple to depend on and easy to maintain. Contributions are welcome, but the scope is intentionally kept narrow: normalize the request/response shape across providers, nothing more (no built-in retries, caching, or routing logic — bring your own if you need them, or build them on top).
Why this exists
Most unified-LLM libraries are either full frameworks (with retries,
caching, cost tracking, routing, and a dozen other opinions baked in)
or tightly coupled to one ecosystem (e.g. LangChain). polygate is
neither — it's the smallest possible layer that lets you swap
providers by changing one string, with each provider adapter being
readable in under 100 lines.
Packages
| Language | Package | Install |
|---|---|---|
| Python | polygate |
pip install polygate |
| TypeScript / JavaScript | polygate |
npm install polygate |
(Not published yet — see CONTRIBUTING.md for running from source.)
Supported providers
| Provider | Aliases | Env var fallback |
|---|---|---|
| Anthropic (Claude) | anthropic, claude |
ANTHROPIC_API_KEY |
| OpenAI | openai, gpt |
OPENAI_API_KEY |
| Google Gemini | gemini, google |
GEMINI_API_KEY |
| Moonshot (Kimi K2) | moonshot, kimi |
MOONSHOT_API_KEY |
The unified message format
Regardless of provider, messages is always a list of:
{ "role": "system" | "user" | "assistant", "content": "..." }
Each adapter translates this into whatever shape the underlying
provider actually expects (e.g. Anthropic's separate system field,
Gemini's contents/model role naming).
The unified response
Every call returns the same shape, regardless of provider:
content— the assistant's reply textrole— always"assistant"model— the model that was actually usedprovider— which provider served the requestusage—{ prompt_tokens, completion_tokens, total_tokens }raw— the untouched, original provider response, for anything not normalized above
Extra parameters
Anything you pass beyond provider, model, messages, api_key,
temperature, and max_tokens is forwarded straight through to the
provider's request payload — so provider-specific options (tools,
top_p, stop sequences, etc.) still work without polygate needing to
know about them ahead of time.
Project layout
polygate/
├── python/ # pip package
├── typescript/ # npm package
├── README.md
├── CONTRIBUTING.md
└── LICENSE
Contributing
See CONTRIBUTING.md. Adding a new provider is usually just: one new adapter file + one line in the registry.
License
MIT — see LICENSE.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file polygate-0.1.0.tar.gz.
File metadata
- Download URL: polygate-0.1.0.tar.gz
- Upload date:
- Size: 6.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cd5c14e4a808dc4f7119ee00a321574587dd61848ff2241f8cdb1d4d250bd7eb
|
|
| MD5 |
590e7e8e2ac8e85744187392185e4b92
|
|
| BLAKE2b-256 |
06c4ef05d7789f48414ad4fa9dde39b767ff4d831b8445b8473f0ce3d0941e4b
|
File details
Details for the file polygate-0.1.0-py3-none-any.whl.
File metadata
- Download URL: polygate-0.1.0-py3-none-any.whl
- Upload date:
- Size: 10.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
260f62ca7fa466aec1033e0e0aa0e3f0d87e6b6d280fcd13342cb859fe9db8ac
|
|
| MD5 |
99b4eaed8c3a5f00503ac15e83dd7d60
|
|
| BLAKE2b-256 |
d3d3351bfba87f1506c6439c6c711b5f72a48487a334022c96bca867147b3914
|