LlaMasterKey


NameLlaMasterKey JSON
Version 0.1.2 PyPI version JSON
download
home_page
SummaryOne master key for all LLM/GenAI endpoints
upload_time2024-02-07 04:47:36
maintainer
docs_urlNone
author
requires_python>=3.10
license
keywords tokens
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # LlaMaKey: one master key for accessing all cloud LLM/GenAI APIs

Introducing LlaMa(ster)Key, the simplified and secure way to manage API keys and control the access to various cloud LLM/GenAI APIs for multiple users. LlaMaKey enables a user to access multiple cloud AI APIs through a one master key unique to the user, instead of a bunch of API keys, one for each platform. As a proxy, it eases key management for both the user and the administrator by consolidating the keys distributed to a user to just one while enhancing the protection of the actual API keys by hiding them from the user. Major cloud AI APIs (OpenAI, Cohere, AnyScale, etc.) can be seamlessly called in their official Python SDKs without any code changes. In addition, administrators can control individual users in detail through rate throttling, API/endpoint whitelisting, budget capping, etc. LlaMaKey is open source under MIT license and is ready for private, on-premises deployment.

```mermaid
graph TD
   subgraph Your team
     A[User 1] -- Master Key 1 --> L["LlaMasterKey server<br> (rate throttling, API/endpoint whitelisting, <br> logging, budgetting, etc.)"]
     B[User 2] -- Master Key 2 --> L
     C[User 100] -- Master Key 100 --> L
   end 
    L -- Actual OPENAI_API_KEY--> O[OpenAI API server]
    L -- Actual CO_API_KEY--> P[Cohere API server]
    L -- Actual VECTARA_API_KEY--> Q[Vectara API server]
```

* **The pain point:** How do you manage the API keys in a team needing to access an array of cloud LLM/GenAI APIs?
If you get one key per user per API, then you have a quadratic number of, or MxN, keys to manage where M is the number of APIs and N is the number of users.
But if you share a key among users, then it is prone to risk and hassles. What if your careless intern accidentally pushes it to a public Github repo? Revoking the key will interrupt the work of all other users.
* **The solution** This is when LlamaKey comes to play. It is a proxy between your users and the actual cloud AI API. A user gets one master key unique to him/her to authenticate with your LlamaKey server which will connect him/her to many cloud AI APIs. Cutting one user loose will not interrupt others. You can even control which APIs each user or user group are allowed to access, their rate limits, budget caps, etc.

Supported APIs:
* [x] OpenAI (all endpoints)
* [x] Cohere (all endpoints)
* [x] AnyScale
* [x] HuggingFace Inference API (free tier)
* [ ] HuggingFace EndPoint API
* [ ] Anthropic
* [ ] Perplexity 
* [ ] Google Vertex AI
* [x] [Vectara AI](https://vectara.com/)

Currently, authentication with the LlaMaKey server is not enabled. All users share the master key `LlaMaKey`. If you want to see it, please [upvote here](https://github.com/TexteaInc/LlaMasterKey/issues/6). 

## How LlaMaKey works 

As a proxy, LlaMaKey takes advantage of a feature in the Python SDK of most cloud LLM/GenAI APIs that they allow setting the base URL and API keys/tokens to and with which a request is sent and authenticated ([OpenAI's](https://github.com/openai/openai-python/blob/d231d1fa783967c1d3a1db3ba1b52647fff148ac/src/openai/_client.py#L95-L108), [Cohere's](https://github.com/cohere-ai/cohere-python/blob/6e035811ecbf33744a5618946371e0e548eb2e73/cohere/client.py#L86-L87)). The base URL and API key can be set easily via environment variables. So a client just needs to set such environment variables (or manually configure in their code) and then call the APIs as usual -- see [how simple and easy](#the-client-end). LlaMaKey will receive the request, authenticate the user (if authentication is enabled), and then forward the request to the corresponding actual cloud API with an actual API key (set by the administrator when starting a LlaMaKey server). The response will be passed back to the client after the LlaMaKey server hears back from a cloud API.

## Installation

* Stable version:

  ```bash
  pip install LLaMasterKey
  ```

* Nightly version (manually install):

  <https://github.com/TexteaInc/LlaMasterKey/releases/tag/nightly>

### Build from source

Requirements: git and  [Rust Toolchain](https://www.rust-lang.org/tools/install). 

```bash
git clone git@github.com:TexteaInc/LlaMasterKey.git 
# you can switch to a different branch:
# git switch dev
cargo build --release
# binary at ./target/release/lmk

# run it without installation
cargo run
# you can also install it system-wide
cargo install --path .

# run it
lmk
```

## Usage

### The server end 
Set up the actual API keys as environment variables per their respective APIs, and then start the server, for example:

```bash
# Set the actual API keys as environment variables 
export OPENAI_API_KEY=sk-xxx # openai
export CO_API_KEY=co-xxx # cohere
export HF_TOKEN=hf-xxx # huggingface
export ANYSCALE_API_KEY=credential-xxx # anyscale

lmk # start the server
```

By default, the server is started at `http://localhost:8000` (8000 is the default port of FastAPI). 

It will generate the shell commands to activate certain environment variables on your client end, like this:
```bash
export OPENAI_BASE_URL="http://127.0.0.1:8000/openai" # direct OpenAI calls to the LlaMaKey server
export CO_API_URL="http://127.0.0.1:8000/cohere"
export ANYSCALE_BASE_URL="http://127.0.0.1:8000/anyscale"
export HF_INFERENCE_ENDPOINT="http://127.0.0.1:8000/huggingface"

export OPENAI_API_KEY="LlaMaKey" # One master key for all APIs
export CO_API_KEY="LlaMaKey"
export ANYSCALE_API_KEY="LlaMaKey"
export HF_TOKEN="LlaMaKey"
```
Such environment variables will direct the API calls to the LlaMaKey server. For your convenience, the commands are also dumped to the file`./llamakey_local.env`.

###  The client end 
Just activate the environment variables generated above and then run your code as usual! 
You may copy and paste the commands above or simply source the `llamakey_local.env` file generated above, for example:

```bash
# step 1: activate the environment variables that tell official SDKs to make requests to LlaMaKey server
source llamakey_local.env 

# Step 2: Call offical Python SDKs as usual, for example, for OpenAI: 
python3 -c '\
from openai import OpenAI;
client = OpenAI();
print (\
  client.chat.completions.create(\
    model="gpt-3.5-turbo",\
    messages=[{"role": "user", "content": "What is FastAPI?"}]
  )
)'
```

## License

Ah, this is important. Let's say MIT for now?

## Contact

For usage, bugs, or feature requests, please open an issue on Github. For private inquiries, please email `bao@textea.co`.

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "LlaMasterKey",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": "",
    "keywords": "tokens",
    "author": "",
    "author_email": "\"Textea Inc.\" <bao@textea.co>",
    "download_url": "https://files.pythonhosted.org/packages/19/db/053d4db8784f5597b902e56b7ef65691c50ecfea0f948779f5894e37e413/LlaMasterKey-0.1.2.tar.gz",
    "platform": null,
    "description": "# LlaMaKey: one master key for accessing all cloud LLM/GenAI APIs\n\nIntroducing LlaMa(ster)Key, the simplified and secure way to manage API keys and control the access to various cloud LLM/GenAI APIs for multiple users. LlaMaKey enables a user to access multiple cloud AI APIs through a one master key unique to the user, instead of a bunch of API keys, one for each platform. As a proxy, it eases key management for both the user and the administrator by consolidating the keys distributed to a user to just one while enhancing the protection of the actual API keys by hiding them from the user. Major cloud AI APIs (OpenAI, Cohere, AnyScale, etc.) can be seamlessly called in their official Python SDKs without any code changes. In addition, administrators can control individual users in detail through rate throttling, API/endpoint whitelisting, budget capping, etc. LlaMaKey is open source under MIT license and is ready for private, on-premises deployment.\n\n```mermaid\ngraph TD\n   subgraph Your team\n     A[User 1] -- Master Key 1 --> L[\"LlaMasterKey server<br> (rate throttling, API/endpoint whitelisting, <br> logging, budgetting, etc.)\"]\n     B[User 2] -- Master Key 2 --> L\n     C[User 100] -- Master Key 100 --> L\n   end \n    L -- Actual OPENAI_API_KEY--> O[OpenAI API server]\n    L -- Actual CO_API_KEY--> P[Cohere API server]\n    L -- Actual VECTARA_API_KEY--> Q[Vectara API server]\n```\n\n* **The pain point:** How do you manage the API keys in a team needing to access an array of cloud LLM/GenAI APIs?\nIf you get one key per user per API, then you have a quadratic number of, or MxN, keys to manage where M is the number of APIs and N is the number of users.\nBut if you share a key among users, then it is prone to risk and hassles. What if your careless intern accidentally pushes it to a public Github repo? Revoking the key will interrupt the work of all other users.\n* **The solution** This is when LlamaKey comes to play. It is a proxy between your users and the actual cloud AI API. A user gets one master key unique to him/her to authenticate with your LlamaKey server which will connect him/her to many cloud AI APIs. Cutting one user loose will not interrupt others. You can even control which APIs each user or user group are allowed to access, their rate limits, budget caps, etc.\n\nSupported APIs:\n* [x] OpenAI (all endpoints)\n* [x] Cohere (all endpoints)\n* [x] AnyScale\n* [x] HuggingFace Inference API (free tier)\n* [ ] HuggingFace EndPoint API\n* [ ] Anthropic\n* [ ] Perplexity \n* [ ] Google Vertex AI\n* [x] [Vectara AI](https://vectara.com/)\n\nCurrently, authentication with the LlaMaKey server is not enabled. All users share the master key `LlaMaKey`. If you want to see it, please [upvote here](https://github.com/TexteaInc/LlaMasterKey/issues/6). \n\n## How LlaMaKey works \n\nAs a proxy, LlaMaKey takes advantage of a feature in the Python SDK of most cloud LLM/GenAI APIs that they allow setting the base URL and API keys/tokens to and with which a request is sent and authenticated ([OpenAI's](https://github.com/openai/openai-python/blob/d231d1fa783967c1d3a1db3ba1b52647fff148ac/src/openai/_client.py#L95-L108), [Cohere's](https://github.com/cohere-ai/cohere-python/blob/6e035811ecbf33744a5618946371e0e548eb2e73/cohere/client.py#L86-L87)). The base URL and API key can be set easily via environment variables. So a client just needs to set such environment variables (or manually configure in their code) and then call the APIs as usual -- see [how simple and easy](#the-client-end). LlaMaKey will receive the request, authenticate the user (if authentication is enabled), and then forward the request to the corresponding actual cloud API with an actual API key (set by the administrator when starting a LlaMaKey server). The response will be passed back to the client after the LlaMaKey server hears back from a cloud API.\n\n## Installation\n\n* Stable version:\n\n  ```bash\n  pip install LLaMasterKey\n  ```\n\n* Nightly version (manually install):\n\n  <https://github.com/TexteaInc/LlaMasterKey/releases/tag/nightly>\n\n### Build from source\n\nRequirements: git and  [Rust Toolchain](https://www.rust-lang.org/tools/install). \n\n```bash\ngit clone git@github.com:TexteaInc/LlaMasterKey.git \n# you can switch to a different branch:\n# git switch dev\ncargo build --release\n# binary at ./target/release/lmk\n\n# run it without installation\ncargo run\n# you can also install it system-wide\ncargo install --path .\n\n# run it\nlmk\n```\n\n## Usage\n\n### The server end \nSet up the actual API keys as environment variables per their respective APIs, and then start the server, for example:\n\n```bash\n# Set the actual API keys as environment variables \nexport OPENAI_API_KEY=sk-xxx # openai\nexport CO_API_KEY=co-xxx # cohere\nexport HF_TOKEN=hf-xxx # huggingface\nexport ANYSCALE_API_KEY=credential-xxx # anyscale\n\nlmk # start the server\n```\n\nBy default, the server is started at `http://localhost:8000` (8000 is the default port of FastAPI). \n\nIt will generate the shell commands to activate certain environment variables on your client end, like this:\n```bash\nexport OPENAI_BASE_URL=\"http://127.0.0.1:8000/openai\" # direct OpenAI calls to the LlaMaKey server\nexport CO_API_URL=\"http://127.0.0.1:8000/cohere\"\nexport ANYSCALE_BASE_URL=\"http://127.0.0.1:8000/anyscale\"\nexport HF_INFERENCE_ENDPOINT=\"http://127.0.0.1:8000/huggingface\"\n\nexport OPENAI_API_KEY=\"LlaMaKey\" # One master key for all APIs\nexport CO_API_KEY=\"LlaMaKey\"\nexport ANYSCALE_API_KEY=\"LlaMaKey\"\nexport HF_TOKEN=\"LlaMaKey\"\n```\nSuch environment variables will direct the API calls to the LlaMaKey server. For your convenience, the commands are also dumped to the file`./llamakey_local.env`.\n\n###  The client end \nJust activate the environment variables generated above and then run your code as usual! \nYou may copy and paste the commands above or simply source the `llamakey_local.env` file generated above, for example:\n\n```bash\n# step 1: activate the environment variables that tell official SDKs to make requests to LlaMaKey server\nsource llamakey_local.env \n\n# Step 2: Call offical Python SDKs as usual, for example, for OpenAI: \npython3 -c '\\\nfrom openai import OpenAI;\nclient = OpenAI();\nprint (\\\n  client.chat.completions.create(\\\n    model=\"gpt-3.5-turbo\",\\\n    messages=[{\"role\": \"user\", \"content\": \"What is FastAPI?\"}]\n  )\n)'\n```\n\n## License\n\nAh, this is important. Let's say MIT for now?\n\n## Contact\n\nFor usage, bugs, or feature requests, please open an issue on Github. For private inquiries, please email `bao@textea.co`.\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "One master key for all LLM/GenAI endpoints",
    "version": "0.1.2",
    "project_urls": null,
    "split_keywords": [
        "tokens"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "653b8ca3884ad2db4885cf8deeededf4964f11b217e759eb59a4173c07dc69a6",
                "md5": "b24df6bcb6cc285e61f1fed1d0f05cc6",
                "sha256": "d7970bc19949f7df5e7980f94ccb46f6b4774f17ab31879357680c5de62779f3"
            },
            "downloads": -1,
            "filename": "LlaMasterKey-0.1.2-py3-none-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl",
            "has_sig": false,
            "md5_digest": "b24df6bcb6cc285e61f1fed1d0f05cc6",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 6751191,
            "upload_time": "2024-02-07T04:47:29",
            "upload_time_iso_8601": "2024-02-07T04:47:29.592024Z",
            "url": "https://files.pythonhosted.org/packages/65/3b/8ca3884ad2db4885cf8deeededf4964f11b217e759eb59a4173c07dc69a6/LlaMasterKey-0.1.2-py3-none-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "ec60b75e10d3226ad1b1e422e99ea49181f1eb9cca8f58af8af84cd87c38920f",
                "md5": "51846bd9564e7cf6b62680b3f3735373",
                "sha256": "3223246eb33148b5126b31e1f03829513cf1b80f2520dfbf8c5733ea4434b683"
            },
            "downloads": -1,
            "filename": "LlaMasterKey-0.1.2-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl",
            "has_sig": false,
            "md5_digest": "51846bd9564e7cf6b62680b3f3735373",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 4960951,
            "upload_time": "2024-02-07T04:47:31",
            "upload_time_iso_8601": "2024-02-07T04:47:31.819890Z",
            "url": "https://files.pythonhosted.org/packages/ec/60/b75e10d3226ad1b1e422e99ea49181f1eb9cca8f58af8af84cd87c38920f/LlaMasterKey-0.1.2-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "d90ffdea492769ac227fd71e0bfe021dd5a3f519011d46afa6d19a76e76a6f1b",
                "md5": "3aec387a8784cc8da69dd40ced247ca1",
                "sha256": "5738a08958c1fc62bb1be80ba49e4774aa0d7c26917cefd2ed4e156aad2226c6"
            },
            "downloads": -1,
            "filename": "LlaMasterKey-0.1.2-py3-none-win_amd64.whl",
            "has_sig": false,
            "md5_digest": "3aec387a8784cc8da69dd40ced247ca1",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 2859277,
            "upload_time": "2024-02-07T04:47:34",
            "upload_time_iso_8601": "2024-02-07T04:47:34.263464Z",
            "url": "https://files.pythonhosted.org/packages/d9/0f/fdea492769ac227fd71e0bfe021dd5a3f519011d46afa6d19a76e76a6f1b/LlaMasterKey-0.1.2-py3-none-win_amd64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "19db053d4db8784f5597b902e56b7ef65691c50ecfea0f948779f5894e37e413",
                "md5": "cc0311053e66ea1705a544caedd3ae93",
                "sha256": "4b731b5285c3ba14c6938f8c45bd09d761481668fdae00314c922a17ef5f172d"
            },
            "downloads": -1,
            "filename": "LlaMasterKey-0.1.2.tar.gz",
            "has_sig": false,
            "md5_digest": "cc0311053e66ea1705a544caedd3ae93",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 27006,
            "upload_time": "2024-02-07T04:47:36",
            "upload_time_iso_8601": "2024-02-07T04:47:36.151208Z",
            "url": "https://files.pythonhosted.org/packages/19/db/053d4db8784f5597b902e56b7ef65691c50ecfea0f948779f5894e37e413/LlaMasterKey-0.1.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-02-07 04:47:36",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "llamasterkey"
}
        
Elapsed time: 2.76273s