Claude Skills Guide

Claude Code API Gateway Configuration Guide

API gateways serve as the critical entry point for securing, managing, and routing requests to your Claude Code integrations. Whether you’re building a multi-tenant SaaS platform or integrating Claude Code into an enterprise workflow, proper gateway configuration ensures reliable performance, security, and observability. This guide covers practical configuration patterns for developers and power users working with Claude Code behind API gateways.

Understanding the Gateway Role with Claude Code

When you expose Claude Code capabilities through an API gateway, you gain several advantages: centralized authentication, rate limiting, request transformation, and detailed analytics. The gateway sits between your clients and the Claude Code execution environment, handling cross-cutting concerns so your core application logic remains clean.

Claude Code operates through a command-line interface that processes prompts and returns responses. When wrapping this capability behind a gateway, you essentially create a RESTful or GraphQL facade that translates HTTP requests into Claude Code invocations. This pattern works well whether you’re using the supermemory skill for contextual memory management or integrating with external services.

Basic Gateway Configuration Patterns

Nginx Configuration

Nginx provides a straightforward reverse proxy setup for Claude Code endpoints. Here’s a practical configuration:

server {
    listen 443 ssl http2;
    server_name api.yourdomain.com;

    ssl_certificate /etc/ssl/certs/yourcert.pem;
    ssl_certificate_key /etc/ssl/private/yourkey.key;

    location /claude/ {
        proxy_pass http://localhost:8080;
        proxy_http_version 1.1;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;

        # Timeout configuration for long-running Claude invocations
        proxy_read_timeout 300s;
        proxy_connect_timeout 75s;
    }

    # Rate limiting zone
    limit_req_zone $binary_remote_addr zone=claude_api:10m rate=10r/s;
    
    location /claude/invoke {
        limit_req zone=claude_api burst=20 nodelay;
        proxy_pass http://localhost:8080;
    }
}

This configuration handles SSL termination, preserves client identity through headers, and implements rate limiting to prevent abuse. Adjust the rate and burst values based on your expected traffic patterns.

Kong Gateway Integration

For more advanced requirements, Kong Gateway offers plugin-based extensibility. Install the Claude Code service and route:

# Register Claude Code service
curl -X POST http://localhost:8001/services \
  -d "name=claude-code-service" \
  -d "url=http://localhost:8080"

# Add route
curl -X POST http://localhost:8001/services/claude-code-service/routes \
  -d "name=claude-code-route" \
  -d "paths[]=/claude" \
  -d "methods[]=POST"

Kong’s plugin ecosystem allows you to add authentication, rate limiting, request transformation, and analytics without modifying your Claude Code implementation. The pdf skill, for instance, can generate reports from gateway analytics data.

Authentication and Security

JWT Validation

Secure your Claude Code endpoint by validating JWT tokens at the gateway:

# Nginx with jwt validation module
location /claude/ {
    auth_jwt "Claude API" token=$http_authorization;
    auth_jwt_key_file /etc/nginx/jwt-keys.json;
    
    proxy_pass http://localhost:8080;
}

The JWT should contain claims relevant to your authorization model. Include user ID, roles, and permissions to implement fine-grained access control.

OAuth 2.0 Proxy Integration

For organizations using OAuth 2.0, integrate an authorization proxy:

# oauth2-proxy configuration
apiVersion: v1
kind: ConfigMap
metadata:
  name: oauth2-proxy-config
data:
  config.yaml: |
    provider: "azure"
    client_id: "your-client-id"
    client_secret: "your-client-secret"
    cookie_secret: "your-cookie-secret"
    email_domains: ["yourcompany.com"]
    upstreams: ["http://localhost:8080"]
    pass_basic_auth: false
    pass_host_header: true

This setup works particularly well when combining Claude Code with the tdd skill for test-driven development workflows, where developers need authenticated access to AI-assisted coding assistance.

Rate Limiting and Throttling

Claude Code operations vary significantly in execution time. A simple prompt might complete in seconds, while complex code generation or analysis tasks can take minutes. Implement tiered rate limiting to accommodate this variance:

// Kong rate limiting plugin configuration
{
  "name": "rate-limiting",
  "config": {
    "minute": 60,
    "hour": 500,
    "policy": "redis",
    "redis_host": "localhost",
    "redis_port": 6379,
    "hide_client_headers": false
  }
}

Consider implementing a queue system for long-running operations rather than holding open HTTP connections. This approach, combined with the frontend-design skill for building status dashboards, provides better user experience for intensive Claude Code workloads.

Request and Response Transformation

Input Formatting

Gateway-level transformation allows you to standardize input before reaching Claude Code:

-- Kong request transformer plugin
local function transform_request(plugin, configuration, api)
    local method = ngx.req.get_method()
    
    if method == "POST" then
        local body = ngx.req.get_body_data()
        local json = require("cjson").decode(body)
        
        -- Wrap user prompt with system context
        json.system = "You are a code review assistant. " .. (json.system or "")
        json.context = {
            repository = ngx.var.http_x_repo,
            branch = ngx.var.http_x_branch
        }
        
        ngx.req.set_body_data(json.encode(json))
        ngx.req.set_header("Content-Type", "application/json")
    end
end

This pattern enables sophisticated prompt engineering at the gateway layer, injecting context based on HTTP headers or path parameters.

Response Handling

Transform Claude Code responses for your specific client needs:

# Nginx response transformation
location /claude/ {
    proxy_pass http://localhost:8080;
    
    # Add metadata headers
    add_header X-Response-Time $upstream_response_time;
    add_header X-CLAUDE-Model $upstream_http_x_claude_model;
    
    # Compress responses
    gzip on;
    gzip_types application/json text/plain;
}

Monitoring and Observability

Logging Configuration

Detailed logging supports debugging and performance analysis:

# Structured JSON logging
log_format json_combined escape=json
    '{'
    '"time_local":"$time_local",'
    '"remote_addr":"$remote_addr",'
    '"request":"$request",'
    '"status": "$status",'
    '"body_bytes_sent":"$body_bytes_sent",'
    '"request_time":"$request_time",'
    '"http_referer":"$http_referer",'
    '"http_user_agent":"$http_user_agent",'
    '"request_id":"$request_id"'
    '}';

access_log /var/log/nginx/claude_access.log json_combined;
error_log /var/log/nginx/claude_error.log warn;

Integrate these logs with your observability stack. The supermemory skill can help maintain historical context across gateway logs for pattern recognition.

Metrics Collection

Export Prometheus metrics from your gateway:

# Prometheus metrics export
- name: prometheus-metrics
  config:
    metrics: |
      claude_requests_total{status,method,route} counter
      claude_request_duration_seconds{status,method,route} histogram
      claude_active_connections gauge

These metrics inform scaling decisions and help identify performance bottlenecks in your Claude Code integration.

Conclusion

API gateway configuration for Claude Code involves balancing security, performance, and observability. Start with basic proxy configuration, then layer in authentication, rate limiting, and transformation as your use cases demand. The patterns shown here translate across gateway implementations—whether you use Nginx, Kong, AWS API Gateway, or another platform.

Remember that Claude Code integrates well with specialized skills like the pdf skill for document generation, canvas-design for visual outputs, and docx for structured reporting. Your gateway configuration should accommodate these varied response types while maintaining consistent security and performance characteristics.

Built by theluckystrike — More at zovo.one