This guide walks you through setting up the AI Proxy plugin with Anthropic.

For all providers, the Kong AI Proxy plugin attaches to route entities.

It can be installed into one route per operation, for example:

  • OpenAI chat route
  • Cohere chat route
  • Cohere completions route

Each of these AI-enabled routes must point to a null service. This service doesn’t need to map to any real upstream URL, it can point somewhere empty (for example, http://localhost:32000), because the AI Proxy plugin overwrites the upstream URL. This requirement will be removed in a later Kong revision.

Prerequisites

  • Anthropic account and subscription
  • You need a service to contain the route for the LLM provider. Create a service first:
  1. curl -X POST http://localhost:8001/services \
  2. --data "name=ai-proxy" \
  3. --data "url=http://localhost:32000"

Remember that the upstream URL can point anywhere empty, as it won’t be used by the plugin.

Provider configuration

After creating an Anthropic account and purchasing a subscription, you can then create an AI Proxy route and plugin configuration.

Set up route and plugin

Kong Admin API

YAML

Create the route:

  1. curl -X POST http://localhost:8001/services/ai-proxy/routes \
  2. --data "name=anthropic-chat" \
  3. --data "paths[]=~/anthropic-chat$"

Enable and configure the AI Proxy plugin for Anthropic, replacing the <anthropic_key> with your own API key:

  1. curl -X POST http://localhost:8001/routes/anthropic-chat/plugins \
  2. --data "name=ai-proxy" \
  3. --data "config.route_type=llm/v1/chat" \
  4. --data "config.auth.header_name=apikey" \
  5. --data "config.auth.header_value=<anthropic_key>" \
  6. --data "config.model.provider=anthropic" \
  7. --data "config.model.name=claude-2.1" \
  8. --data "config.model.options.max_tokens=512" \
  9. --data "config.model.options.temperature=1.0" \
  10. --data "config.model.options.top_p=256" \
  11. --data "config.model.options.top_k=0.5"
  1. name: anthropic-chat
  2. paths:
  3. - "~/anthropic-chat$"
  4. methods:
  5. - POST
  6. plugins:
  7. - name: ai-proxy
  8. config:
  9. route_type: "llm/v1/chat"
  10. auth:
  11. header_name: "apikey"
  12. header_value: "<anthropic_key>" # add your own Anthropic API key
  13. model:
  14. provider: "anthropic"
  15. name: "claude-2.1"
  16. options:
  17. max_tokens: 512
  18. temperature: 1.0
  19. top_p: 256
  20. top_k: 0.5

Test the configuration

Make an llm/v1/chat type request to test your new endpoint:

  1. curl -X POST http://localhost:8000/anthropic-chat \
  2. -H 'Content-Type: application/json' \
  3. --data-raw '{ "messages": [ { "role": "system", "content": "You are a mathematician" }, { "role": "user", "content": "What is 1+1?"} ] }'

Previous Configure Streaming with AI Proxy

Next Set up AI Proxy with Azure OpenAI Service