Apache APISIX

repository·master·Indexed 12 days ago

https://github.com/apache/apisix

A high-performance, dynamic API Gateway built on NGINX and etcd for real-time traffic management and AI workload orchestration. It supports multi-protocol proxying (HTTP/3, gRPC, MQTT, Dubbo), dynamic routing, load balancing, and a rich plugin system for security, observability, and AI proxying. Features include a Kubernetes ingress controller, an Admin API for configuration, and a visual management dashboard.

Tokens
391.6K
Snippets
901
Records
1.3K
Agent score
95%

What's inside APISIX

  1. Overview of the ai-proxy Plugin

    master

    The ai-proxy plugin simplifies access to Large Language Model (LLM) and embedding model providers. It acts as a transformer, converting APISIX plugin configurations into the specific request formats required by various providers, including:

    • OpenAI
    • DeepSeek
    • Azure
    • AIMLAPI
    • Anthropic
    • OpenRouter
    • Gemini
    • Vertex AI
    • Amazon Bedrock
    • Other OpenAI-compatible APIs

    Additionally, the plugin can log LLM request metadata (such as token usage, model name, and time to first response) into the access log. These logs are compatible with logging plugins like http-logger and kafka-logger. Note that these logs are sent to the access log and do not affect error.log.

  2. Overview of Apache APISIX

    master
    Apache APISIX is a dynamic, real-time, high-performance API Gateway built on top of NGINX and etcd. It provides rich traffic management features including load balancing, dynamic upstream, canary release, circuit breaking, authentication, and observability. It is designed to handle both north-south traffic (client-to-server) and east-west traffic (service-to-service) and can function as a Kubernetes ingress controller.
  3. Overview of the openid-connect plugin

    master
    The openid-connect plugin enables integration with OpenID Connect (OIDC) identity providers (e.g., Keycloak, Auth0, Microsoft Entra ID, Google, Okta). It allows Apache APISIX to authenticate clients and retrieve their information from the identity provider. Based on the authentication result, APISIX can then allow or deny access to protected upstream resources.
  4. Overview of the ai-proxy-multi Plugin

    master

    The ai-proxy-multi plugin is an extension of the ai-proxy plugin designed to simplify access to Large Language Models (LLMs) and embedding models. It acts as a proxy that transforms plugin configurations into the specific request formats required by various providers, including OpenAI, DeepSeek, Azure, AIMLAPI, Anthropic, OpenRouter, Gemini, Vertex AI, and Amazon Bedrock.

    Key features include:

    • Advanced Reliability: Adds load balancing, retries, fallbacks, and health checks to LLM requests.
    • Observability: Supports logging LLM-specific metadata in the access log, such as token usage, model name, and time to first response. These logs are compatible with logging plugins like http-logger and kafka-logger.
  5. Overview of the Lago Billing plugin

    master

    The lago plugin enables API monetization by reporting usage data to Lago Self-hosted or Lago Cloud via the Lago REST API. It is particularly useful for billing scenarios like AI token consumption or standard API call metering.

    Key features:

    • Collects request/response context (event codes, transaction IDs, subscription IDs).
    • Serializes data into Event JSON objects.
    • Uses a batching mechanism to send up to 100 events at once to meet Lago's requirements.
    • Integrates with APISIX features like the consumer and request-id plugins to dynamically map usage to specific customers and subscriptions.
  6. Use the graphql-limit-count Plugin

    master

    The graphql-limit-count plugin limits the rate of GraphQL requests using a fixed window algorithm. Unlike the standard limit-count plugin which counts requests, this plugin uses the depth of the GraphQL query AST as the cost. This allows you to enforce stricter limits on deeply nested, computationally expensive queries.

    Supported Request Types

    • Method: Only POST requests are supported.
    • Content-Types:
      • application/json: The request body must contain a query field with the GraphQL query string.
      • application/graphql: The request body is the raw GraphQL query starting with query.

    Rate Limiting Headers

    When show_limit_quota_header is set to true (default), the following headers are included in the response:

    • X-RateLimit-Limit: The total quota.
    • X-RateLimit-Remaining: The remaining quota.
    • X-RateLimit-Reset: Number of seconds left for the counter to reset.
    curl -i "http://127.0.0.1:9080/graphql" \
      -H "Content-Type: application/json" \
      -d '{"query": "query { foo { bar { baz { id } } } }"}'
  7. Use the oas-validator plugin for request validation

    master

    The oas-validator plugin validates incoming HTTP requests against an OpenAPI Specification (OAS) 3.x document. It can validate the request method, path, query parameters, request headers, and body. If a request fails validation, the plugin can reject it with a configurable HTTP status code or simply log the failure and allow the request to proceed to the upstream service.

    To use this plugin, you must provide either an inline JSON specification via the spec attribute or a remote URL via the spec_url attribute.

    # Example: Configure a route with an inline spec
    curl "http://127.0.0.1:9180/apisix/admin/routes" -X PUT \
      -H "X-API-KEY: ${admin_key}" \
      -d '{
        "id": "oas-validator-route",
        "uri": "/api/v3/*",
        "plugins": {
          "oas-validator": {
            "spec": "{\"openapi\":\"3.0.2\",\"info\":{\"title\":\"Pet API\",\"version\":\"1.0.0\"},\"paths\":{\"/api/v3/pet\":{\"post\":{\"requestBody\":{\"required\":true,\"content\":{\"application/json\":{\"schema\":{\"type\":\"object\",\"required\":[\"name\"],\"properties\":{\"name\":{\"type\":\"string\"},\"status\":{\"type\":\"string\"}}}}}},\"responses\":{\"200\":{\"description\":\"OK\"}}}}}}",
            "verbose_errors": true
          }
        },
        "upstream": {
          "type": "roundrobin",
          "nodes": {"httpbin.org:80": 1}
        }
      }'
  8. Use the tcp-logger plugin to push logs to TCP servers

    master

    The tcp-logger plugin sends log data as JSON objects to an external TCP server. It supports both real-time sending and batch processing to improve efficiency. When using the batch processor, logs are sent every 5 seconds or when the queue reaches 1000 entries (unless configured otherwise).

    curl http://127.0.0.1:9180/apisix/admin/routes/5 -H "X-API-KEY: $admin_key" -X PUT -d '
    {
          "plugins": {
                "tcp-logger": {
                     "host": "127.0.0.1",
                     "port": 5044,
                     "tls": false,
                     "batch_max_size": 1,
                     "name": "tcp logger"
                }
           },
          "upstream": {
               "type": "roundrobin",
               "nodes": {
                   "127.0.0.1:1980": 1
               }
          },
          "uri": "/hello"
    }'
  9. Use the ai-lakera-guard plugin for AI security

    master

    The ai-lakera-guard plugin integrates Apache APISIX with the Lakera Guard API (v2) to perform ML-based security scanning of LLM traffic. It inspects requests for prompt injection, jailbreak, PII leakage, content-policy violations, and malicious links.

    Key Requirements:

    • Must be used with either the ai-proxy or ai-proxy-multi plugin to ensure the plugin can extract chat content in a protocol-aware way.
    • Requests that do not pass through ai-proxy/ai-proxy-multi (e.g., plain HTTP traffic) cannot be inspected and are handled based on the fail_mode setting.

    Core Logic:

    • The plugin relies on a project_id to determine which detectors and thresholds to apply via the Lakera project policy.
    • It can scan the request (input), the response (output), or both (both).
  10. Use the Open Policy Agent (OPA) plugin for authorization

    master

    The opa plugin integrates Apache APISIX with Open Policy Agent (OPA) to enable unified policy enforcement. When a client request hits a protected Route, APISIX sends request metadata to the OPA engine. OPA evaluates the request against policies written in Rego and returns a decision.

    To work correctly, your OPA policy must return an object containing an allow field. You can also optionally include reason, headers, and status_code in the OPA response to customize the authorization outcome.

  11. Use the ai-rag plugin for Retrieval-Augmented Generation

    master

    The ai-rag plugin enhances Large Language Model (LLM) outputs by using Retrieval-Augmented Generation (RAG). It retrieves relevant documents from external data sources to improve the accuracy and contextual relevance of LLM responses.

    Currently, the plugin supports:

    • Azure OpenAI for generating embeddings.
    • Azure AI Search for performing vector searches.