Skip to main content
Code Gateway is an enterprise proxy gateway that routes LLM API requests from AI coding CLI tools (Claude Code, Cursor, Codex CLI, Gemini CLI, GitHub Copilot, etc.) through Cloosphere. Centralize the management of AI coding tool usage with guardrails, usage tracking, audit logs, and rate limits.
Code Gateway settings main screen

Concept

ComponentDescription
DevelopersSet Cloosphere Code Gateway as BASE_URL in AI coding tools
Code GatewayPerforms authentication, guardrails, rate limiting, usage tracking, then proxies to upstream provider
LLM ProviderService that actually provides the LLM API (OpenAI, Anthropic, Azure, etc.)
Code Gateway is backend-API-dedicated and operates separately from chat in the Cloosphere web UI. Configure only in admin settings — users set Cloosphere API keys in their coding tools.

Activation and Setup

Enabling Code Gateway

1

Open admin settings

Navigate to the Code Gateway settings page in the admin panel.
2

Activate the gateway

Toggle on Enable Code Gateway.
3

Add Provider

Click + Add Provider to register an LLM Provider.
4

Security settings

Configure allowed models, rate limits, guardrails, file pattern blocks.
Code Gateway activation and full settings

Global Settings

SettingDescriptionDefault
EnabledCode Gateway ON/OFFOFF
Allowed modelsList of usable models (empty = allow all)All
Rate limitMax requests per minute per user (0 = unlimited)0
GuardrailsList of guardrail IDs to applyNone
File pattern blockFile patterns to block (glob format)None
File block actionBehavior on block (block / warn)block
Blocked repositoriesRepository patterns to block AI coding tool usageNone
Require repository metadataBlock requests without helper script setupOFF

Provider Settings

A Provider is the upstream LLM service Code Gateway forwards requests to. Multiple Providers can be registered simultaneously, each identified by a unique provider_id.

Supported Providers

TypeServiceAuth Method
openaiOpenAI, OpenAI-compatible endpointsBearer token
anthropicAnthropic APIx-api-key header
geminiGoogle Gemini APIx-goog-api-key header
azure_openaiAzure OpenAI Serviceapi-key header
azure_ai_foundryAzure AI Foundryapi-key header
vertex_aiGoogle Vertex AI (native)GCP Service Account

Provider Presets

Picking a preset when adding a Provider auto-sets the type and base URL.
Azure AI Foundry has two sub-presets:
  • Azure AI Foundry - OpenAI: For OpenAI-compatible models (openai type). Use with Cursor, Codex CLI, GitHub Copilot.
  • Azure AI Foundry - Claude: For Claude models (azure_ai_foundry type). Use with Claude Code, Cursor.
For the same AI Foundry endpoint, pick the appropriate preset based on the models you’re using.

Adding a Provider

Add Code Gateway Provider
SettingDescription
Provider IDUnique identifier (used in URL path)
Typeopenai / anthropic / gemini
API URLProvider API endpoint
API KeyAuthentication key
Model IDsList of allowed models for this Provider (empty = all)
EnabledProvider ON/OFF

Developer Usage

Developers set the BASE_URL of their AI coding tools to Cloosphere Code Gateway and use a Cloosphere API key.

Endpoint Structure

{CLOOSPHERE_URL}/api/v1/code-gateway/{provider_id}/{path}
Examples:
  • OpenAI Provider: https://cloosphere.company.com/api/v1/code-gateway/openai/v1/chat/completions
  • Anthropic Provider: https://cloosphere.company.com/api/v1/code-gateway/anthropic/v1/messages

Authentication

Code Gateway accepts API keys in four ways (in priority order).
MethodHeader/ParameterTools
Bearer TokenAuthorization: Bearer {api_key}Cursor, Codex CLI, GitHub Copilot
x-api-keyx-api-key: {api_key}Claude Code (Anthropic SDK)
x-goog-api-keyx-goog-api-key: {api_key}Gemini CLI
Query Parameter?key={api_key}Fallback
Generate API keys in the API Keys section of Cloosphere user settings. Use the Cloosphere API key, not the Provider’s original API key.

Per-Tool Setup Examples

# .bashrc or .zshrc
export ANTHROPIC_BASE_URL="https://cloosphere.company.com/api/v1/code-gateway/anthropic"
export ANTHROPIC_API_KEY="sk-cloosphere-..."

Claude Code Setup Script

An auto-setup script is provided for Claude Code users. It auto-installs the helper script and configures ~/.claude/settings.json.
# 1. Set environment variables
export ANTHROPIC_AUTH_TOKEN="sk-cloosphere-..."
export ANTHROPIC_BASE_URL="https://cloosphere.company.com/api/v1/code-gateway/anthropic"

# 2. Run setup script
curl -s https://cloosphere.company.com/api/v1/code-gateway/setup-script | bash
What the setup script does:
  1. Install helper script (~/cloosphere-helper.sh or ~/cloosphere-helper.ps1): Auto-attach repository metadata (Git remote URL, working directory) to API keys
  2. Configure ~/.claude/settings.json: Auto-set ANTHROPIC_AUTH_TOKEN, ANTHROPIC_BASE_URL, apiKeyHelper
The helper script is required in environments with repository metadata-based blocking policies (blocked_repos, require_repo_metadata) enabled.

Security Features

Guardrails

Apply guardrails to Code Gateway for PII detection, content filtering, etc., on coding tool inputs. Specify guardrail IDs created in Guardrail Management. Guardrail violations, file pattern blocks, repository blocks, and other events are all viewable in the Monitoring > Guardrail Logs tab.
Code Gateway security settings

Allowed Models

Restrict to specific models. Configurable at both global and Provider levels.
LevelSetting FieldDescription
Global allowed modelsallowed_modelsModels usable across the entire Code Gateway (global setting)
Provider model IDsmodel_idsModels allowed per Provider (per-Provider setting)
When both allowed_models (global) and model_ids (per Provider) are set, only models allowed by both are usable. allowed_models is the Code Gateway-wide policy; model_ids adds per-Provider restriction.

Rate Limit

Limit max requests per minute per user. Operates on a 60-second sliding window.
Rate limits are in-memory, so they reset on server restart.

File Pattern Block

Block files matching specific patterns in coding tool requests. Specify patterns in glob format.
SettingDescriptionExample
PatternFile path patterns to block*.env, *credentials*, *.pem
Actionblock (block request) or warn (log only)block

Blocked Repositories

Block AI coding tool usage in specific Git repositories. Matching is based on repository metadata (repo URL, working directory) passed via the helper script.
SettingDescriptionExample
Block patternsRepository URL or path patterns to block (substring matching)secret-project, github.com/org/private-repo
Patterns are case-insensitive substring matched against repository URL and working directory path. Git SSH URLs (git@github.com:org/repo.git) are auto-normalized for matching.
Blocked repository access is auto-recorded in the guardrail log.

Require Repository Metadata

Enabling require_repo_metadata blocks requests without repository metadata via the helper script. This forces all Code Gateway users to set up the helper script.
Enabling this option blocks all requests from users without the helper script. Inform users to set up the helper script before enabling.

Usage Tracking

All requests through Code Gateway are auto-logged for usage. Admins can review usage logs to see per-team, per-user, per-model usage.
ItemDescription
UserRequesting user
ModelLLM model used
ProviderProvider used
Input/output tokensRequest/response token counts
TimeRequest time

Usage Statistics

View per-period usage statistics to analyze cost and trends.

Filters

FilterDescription
UserFilter by specific user
ModelFilter by specific model
PeriodStart ~ end date

Proxy Processing Flow

The full flow Code Gateway uses to process requests:

Troubleshooting

Code Gateway is disabled in admin settings. Ask an admin to enable it.
The user’s feature permissions don’t include Code Gateway access. Admin must enable features.code_gateway in group permission settings.
The provider_id in the request URL doesn’t match a registered Provider. Verify Provider ID.
The requested model isn’t in the global allowed models or the Provider’s allowed models list. Ask an admin to add the model.
You’ve exceeded the per-minute request limit. Wait briefly and retry.
require_repo_metadata is enabled but the helper script isn’t configured. Run the Claude Code setup script to install the helper script.
The request’s repository URL or working directory matches a blocked_repos pattern. Ask an admin for unblock.