# AI gateway

7 endpoints at `https://api.kosa8.com`, sent with `Authorization: Bearer $KOSA8_API_KEY`. Generated from the API's own [OpenAPI description](https://api.kosa8.com/openapi.json), which a test holds to the router.

## Provider keys stored for the AI gateway (last 4 characters only)[#]

GET`/v1/ai/keys`scope admin

Responses

200401403

```
curl -s -X GET https://api.kosa8.com/v1/ai/keys \
  -H "Authorization: Bearer $KOSA8_API_KEY"
```

## Store the org's own provider key (sealed; never returned, never sent into a sandbox)[#]

PUT`/v1/ai/keys/{provider}`scope admin

Parameters

`provider`requiredpath · string

One of openai, anthropic, groq, mistral, deepseek, openrouter, google-ai-studio, workers-ai

JSON body

`key`requiredstring

—

Responses

200400401403

```
curl -s -X PUT https://api.kosa8.com/v1/ai/keys/$PROVIDER \
  -H "Authorization: Bearer $KOSA8_API_KEY" \
  -H 'Content-Type: application/json' -d @body.json
```

## Remove a provider key[#]

DELETE`/v1/ai/keys/{provider}`scope admin

Parameters

`provider`requiredpath · string

One of openai, anthropic, groq, mistral, deepseek, openrouter, google-ai-studio, workers-ai

Responses

200401403404

```
curl -s -X DELETE https://api.kosa8.com/v1/ai/keys/$PROVIDER \
  -H "Authorization: Bearer $KOSA8_API_KEY"
```

## The AI gateway's settings, base URL and configured providers[#]

GET`/v1/ai/settings`scope sandboxes:read

Responses

200401403

```
curl -s -X GET https://api.kosa8.com/v1/ai/settings \
  -H "Authorization: Bearer $KOSA8_API_KEY"
```

## Change the AI gateway's settings[#]

PATCH`/v1/ai/settings`scope admin

JSON body

`enabled`boolean

—

`all_sandboxes`boolean

Put the gateway in every new sandbox (ai_gateway: false opts one out)

`cache_ttl_s`integer

AI Gateway response cache; 0 is off Min 0. Max 86400.

`rate_per_min`integer

Model calls a minute for the org Min 1. Max 6000.

Responses

200400401403

```
curl -s -X PATCH https://api.kosa8.com/v1/ai/settings \
  -H "Authorization: Bearer $KOSA8_API_KEY" \
  -H 'Content-Type: application/json' -d @body.json
```

## Model spend through the gateway: totals, by provider and model, by sandbox, recent calls[#]

GET`/v1/ai/usage`scope sandboxes:read

Cost is AI Gateway's price for each call; the provider bills it to the org's own key, not kosa8.

Parameters

`month`query · string

—

Responses

200401403

```
curl -s -X GET https://api.kosa8.com/v1/ai/usage \
  -H "Authorization: Bearer $KOSA8_API_KEY"
```

## A model call through the AI gateway, in the provider's own request shape[#]

POST`/v1/ai/gw/{provider}/{path}`public

Send a sandbox's KOSA8_AI_TOKEN (or an API key with sandboxes:write) as the provider SDK's API key, as Authorization: Bearer or x-api-key. A sandbox created with ai_gateway: true has OPENAI_BASE_URL, ANTHROPIC_BASE_URL and the like set to this path already. The org's stored key for the provider is attached here; the call is logged, costed and tagged with the org and sandbox in Cloudflare AI Gateway.

Parameters

`provider`requiredpath · string

One of openai, anthropic, groq, mistral, deepseek, openrouter, google-ai-studio, workers-ai

`path`requiredpath · string

The provider's API path, e.g. chat/completions (openai) or v1/messages (anthropic)

Responses

200400401402403404409413429502

```
curl -s -X POST https://api.kosa8.com/v1/ai/gw/$PROVIDER/$PATH
```

---
Source: https://docs.kosa8.com/api/ai-gateway/
