Skip to main content

What is AI gateway?

Keywords AI’s AI Gateway is a gateway that lets you interface with 250+ large language models (LLMs) via one unified API.

Considerations:

  • May not be suitable for products with strict latency requirements (50 - 150ms added).
  • May not be ideal for those who do not want to integrate a third-party service into the core of their application.

Use AI gateway

1. Get your Keywords AI API key

After you create an account on Keywords AI, you can get your API key from the API keys page.
Create API key placeholder

2. Set up LLM provider API key

Environment Management: To separate test and production environments, create separate API keys for each environment instead of using an env parameter. This approach provides better security and clearer separation between your development and production workflows.
For all AI gateway users, you have to add your own credentials to activate AI gateway. We will use your credentials to call LLMs on your behalf.
For example, if you want to use OpenAI, you have to add your OpenAI API key to activate AI gateway. We won’t use your credentials for any other purposes.

3. Call a LLM

You can use the standard API call to connect 250+ LLMs.
import requests
def demo_call(input, 
              model="gpt-4o-mini",
              token="YOUR_KEYWORDS_AI_API_KEY"
              ):
    headers = {
        'Content-Type': 'application/json',
        'Authorization': f'Bearer {token}',
    }

    data = {
        'model': model,
        'messages': [{'role': 'user', 'content': input}],
    }

    response = requests.post('https://api.keywordsai.co/api/chat/completions', headers=headers, json=data)
    return response

messages = "Say 'Hello World'"
print(demo_call(messages).json())

4. Parameters

We support all OpenAI parameters, which is the standard format for LLMs. You can check out important OpenAI parameters in this page. You can also learn more about OpenAI parameters here.
Use these when you want to achieve specific goals. For example, you can use fallback_models to specify fallback models when the primary model is down. You can check out all Keywords AI parameters in this page.

Integrate with your existing AI framework

Keywords AI offers various integration options, including all mainstream LLM frameworks and REST APIs.

Supported frameworks

OpenAI SDK

LangChain SDK

Vercel AI SDK

LlamaIndex SDK

Google GenAI

Anthropic
I