Hermes Agent
Connect Hermes Agent to Cloudflare AI Gateway
Updated 28 November 2026
Hermes runs the agent. Cloudflare AI Gateway takes its model requests and forwards them to the provider. For a new single-model chat, use Cloudflare’s account REST API as a custom endpoint in Hermes. For a third-party model on the default gateway, Hermes sends one Cloudflare token. Cloudflare can then use a stored provider key or your prepaid credits to make the call.
The settings below come from the Hermes Agent 0.23.5 provider guide and request options, and from Cloudflare’s REST API reference and OpenAI compatibility guide, read on 28 November 2026. The hosted limits below come from the ReadyHermes Model key panel.
Prepare the account, token and model payment
- Find your account ID in the Cloudflare dashboard. Create a Cloudflare API token with the account permission Workers AI → Read. The account inference API requires this permission even for a model hosted by OpenAI.
- Choose how to pay for model usage. If you use your own provider key, the provider bills you directly. For Unified Billing, add a non-prepaid credit or debit card in Cloudflare’s Billing settings and make it your primary payment method. In AI Gateway, select Manage under Credits Available, then Top-up credits. Enter an amount and select Confirm and pay. In rare cases, your balance can go negative and Cloudflare charges your payment method for the outstanding amount. Cloudflare can create the
defaultgateway on your first authenticated third-party request. - To use your own provider key instead, open the
defaultgateway under AI → AI Gateway. If you need to create it first, select Create Gateway and name itdefault. Under Provider Keys, select Add API Key. To bill the example modelopenai/gpt-4.1to your OpenAI account, choose OpenAI and save its key with the aliasdefault. You need Secrets Store permissions. If you use another provider, save its key under the same alias and use a supported model ID from that provider in the steps below.
Both stored keys and Unified Billing require an authenticated gateway. When Cloudflare finds no applicable provider key, it can fall back to prepaid credits. Turn on Require provider credentials if you want that third-party call to fail instead. See Cloudflare’s stored-key setup and billing and credential order.
Point Hermes at the account REST API
On the machine running Hermes, run hermes model in a terminal. Choose Custom endpoint (enter URL manually). Enter the base URL shown below with your account ID, then enter the Cloudflare token as the API key. If Hermes warns that it could not verify the model list, keep the URL. Choose Chat Completions, then enter your model ID (for example, openai/gpt-4.1). You can leave the context length blank and accept the suggested display name. Hermes adds /chat/completions to the base URL.
To enter the same settings by hand, put the Cloudflare token in ~/.hermes/.env under the name CLOUDFLARE_API_TOKEN. Use the following as the model section of ~/.hermes/config.yaml, replacing the account ID placeholder.
model:
provider: custom
default: openai/gpt-4.1
base_url: https://api.cloudflare.com/client/v4/accounts/<ACCOUNT_ID>/ai/v1
api_mode: chat_completions
key_env: CLOUDFLARE_API_TOKENThe token goes in Authorization as a bearer credential. For third-party models, omitting cf-aig-gateway-id selects the default gateway. To use another gateway, create it in Cloudflare first. To keep billing your provider account, save your provider key on the new gateway under the default alias. Without that key, the call can use prepaid credits if fallback is allowed, or fail if the gateway requires provider credentials. In the configuration above, add default_headers under model. Under default_headers, set cf-aig-gateway-id to your gateway ID.
Workers AI models beginning with @cf/ require the same header even on the default gateway, where its value is default. Workers AI uses Standard billing by default. For prepaid credits, Cloudflare documents a separate request with the model ID in the URL. In the gateway’s Settings, change Workers AI Billing to Unified billing and select Save.
Two similar names in Hermes point elsewhere. The built-in ai-gateway provider connects to Vercel. The community cloudflare-workers-ai-provider plugin serves Workers AI models. Third-party routing through Cloudflare uses the custom endpoint above.
Choose the model ID for an existing gateway URL
Cloudflare deprecates /compat/chat/completions for standard single-model calls and recommends the account REST endpoint /ai/v1/chat/completions. Existing integrations can continue to use the compatibility endpoint. Its full base URL is https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/compat. Substitute both IDs. For a provider-specific base URL, replace /compat with the path for your provider and API mode below. If you send your own provider key through an authenticated gateway, also send cf-aig-authorization: Bearer {CF_AIG_TOKEN}, replacing the placeholder with your Cloudflare token.
| Gateway path | What to send |
|---|---|
/compat | Send a chat completion with a provider-prefixed model such as openai/gpt-5-mini. An existing dynamic route uses dynamic/{route} in the same model field. |
/openai | Use the OpenAI model ID, such as gpt-4o-mini. The request goes to /openai/chat/completions. |
/openrouter | Use the OpenRouter model ID, such as openai/gpt-5-mini. Cloudflare’s SDK example uses this base. Its cURL example adds /v1 before /chat/completions, while its URL description omits it. For an OpenAI client, follow the SDK base. |
/anthropic/v1 | Choose Chat Completions. Cloudflare accepts a provider bearer token at /anthropic/v1/chat/completions. |
/anthropic | Choose Anthropic Messages. At /anthropic/v1/messages, Cloudflare accepts the provider key in x-api-key. |
For either Anthropic path, enter Anthropic’s own model ID in Hermes. For example, Cloudflare lists anthropic/claude-opus-4.8 in its catalogue, and Anthropic uses claude-opus-4-8 for the same model. See Cloudflare’s Claude Opus 4.8 model page.
Cloudflare documents the provider paths in its OpenAI, OpenRouter and Anthropic guides.
Send a gateway token and an OpenAI key from Hermes
For an authenticated gateway on the gateway hostname, you can supply your own OpenAI key with each request. Hermes sends the OpenAI key in Authorization. The separate Cloudflare token goes in cf-aig-authorization. In the gateway’s Settings, select Create authentication token and save the AI Gateway → Run token securely when it appears. Cloudflare shows it only once. Anyone with it can send requests through every gateway in the account, including requests that use those gateways’ stored provider keys.
Since 3 November 2026, Cloudflare requires authentication for new gateways. An older gateway with authentication still off can accept the OpenAI key alone. Enabling authentication blocks unauthorised requests and helps reduce invalid traffic in the logs. Before you turn authentication on, configure every HTTP client using that gateway to send a valid Cloudflare token. If ReadyHermes uses the old gateway URL with only an OpenAI key, switch to the account REST setup described below and check that the test message succeeds first. Once enabled, gateway authentication stays on.
For the two-key setup, put the keys in ~/.hermes/.env as OPENAI_API_KEY and CF_AIG_TOKEN. Use the following settings in ~/.hermes/config.yaml in place of the account REST example. Replace the two IDs in the URL. The named provider keeps its extra_headers on requests to that base URL.
model:
provider: custom:my-gateway
default: gpt-4o-mini
providers:
my-gateway:
api: https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/openai
key_env: OPENAI_API_KEY
transport: chat_completions
extra_headers:
cf-aig-authorization: "Bearer ${CF_AIG_TOKEN}"With a stored key or Unified Billing, Cloudflare’s raw HTTP examples send just the gateway token in cf-aig-authorization. A provider credential in the request takes priority, so even a dummy provider key can cause an authentication error. The OpenAI SDK examples for these modes put the Cloudflare token alone in apiKey. For the two-key configuration above, the SDK and HTTP examples agree on the two distinct headers. See the gateway authentication rules.
Verify the first chat and diagnose a failed request
Start a fresh session with hermes and ask a short question. After the reply, open the intended gateway in the Cloudflare dashboard and check its logs for the request at that time. With logging enabled, check that the provider and timestamp match your test.
- Account API returns 401 with code 10000. Check the token’s permissions. A token with only AI Gateway permissions cannot make account inference calls. It needs Workers AI Read.
- The model list is empty. The account REST API has no
/v1/modelslisting. Enter the model ID directly. On a named Hermes provider,discover_models: falseand amodelslist let the picker use your IDs without probing the endpoint.
What Cloudflare logs, caches and charges for
Gateway logging is on by default. Entries can include prompts, replies, token usage and cost. If you manage Hermes yourself, send the header cf-aig-collect-log-payload: false to keep request metadata while omitting that request’s prompt and reply from the gateway log. The ReadyHermes Model key panel cannot send this header. To turn logging off for the gateway, open its Settings in Cloudflare and switch Logs off. If you have configured Logpush, it still exports encrypted request and response bodies even when gateway logging or payload collection is off. With logging off, Unified Billing still records billing details and request metadata. See Cloudflare’s log settings and Logpush documentation.
- Caching. Enable caching in the dashboard if you want matching requests to reuse a response. It starts off. With the default cache key, changing the messages, tools or model parameters changes the key. The response header
cf-aig-cache-statusreportsHITorMISS. - Rate limits. You can set a request limit for your gateway. Cloudflare also limits requests using its managed Unified Billing credentials to 200 per 60 seconds per gateway. Exceeding that limit returns HTTP
429with error code2018. Requests using your own provider key are exempt from this billing limit. See Cloudflare’s gateway limits. - Fallbacks. A gateway model alias can try eligible models in the order you set. Cloudflare recommends dynamic routes for new fallback configurations. To put the backup in Hermes itself, see Hermes fallback models.
- Cost. Dashboard analytics, caching and rate limiting are free on all Cloudflare plans. Model usage and log storage have separate pricing. Unified Billing uses the provider’s per-token price and adds a 5% fee when you buy credits. See AI Gateway pricing.
Cloudflare AI Gateway on ReadyHermes
We have not tested Cloudflare AI Gateway with ReadyHermes. For a new setup, use the account REST route. Open Model key in your ReadyHermes account, choose Your own API key, then Other endpoint. For the default gateway, enter the account REST base URL and your Cloudflare token, type your model ID (for example, openai/gpt-4.1), and select Switch to my key. ReadyHermes sends a small test message. If it succeeds, the assistant restarts on the new key in about a minute. See the Model key overview.
The panel accepts a public HTTPS hostname on port 443, with an optional path and no query string. It sends one credential, Authorization: Bearer <key>. That format matches a third-party model on the default account REST gateway. It also matches OpenAI chat with an OpenAI key on an older gateway that still has authentication off. The panel cannot add cf-aig-authorization alongside a provider key, or cf-aig-gateway-id to select another account REST gateway or route a Workers AI model. Cloudflare’s one-token SDK examples for stored keys and credits on the gateway hostname are unverified with this panel.
Questions
Which Cloudflare URL does Hermes Agent use for a new chat?
Use https://api.cloudflare.com/client/v4/accounts/<ACCOUNT_ID>/ai/v1 as the custom base URL, replacing the account ID. Hermes adds /chat/completions. Cloudflare deprecates /compat/chat/completions for standard single-model calls and keeps it available for existing integrations.
Which key goes into Hermes for the default account REST gateway?
Use a Cloudflare token with Account → Workers AI → Read. Hermes sends it as a bearer token. For a third-party model, Cloudflare looks for the default key for the provider named in the model ID. Without that key on the gateway, the call can use prepaid credits if fallback is allowed, or fail if the gateway requires provider credentials.
How can Hermes send cf-aig-authorization and an OpenAI key together?
On a self-managed installation, store the OpenAI key as OPENAI_API_KEY and the Cloudflare token as CF_AIG_TOKEN in ~/.hermes/.env. In the named provider’s settings in ~/.hermes/config.yaml, set key_env to OPENAI_API_KEY. Under extra_headers, set cf-aig-authorization to Bearer ${CF_AIG_TOKEN}. The Cloudflare token needs AI Gateway Run permission.
Can Hermes use a Cloudflare model if the model picker is empty?
Yes. Enter the model ID directly, such as openai/gpt-4.1 on the account REST endpoint. That endpoint has no model listing. A named Hermes provider can also use an explicit models list with discover_models set to false.
Can ReadyHermes send the extra Cloudflare gateway header?
The Other endpoint panel sends one Authorization bearer key. It cannot add cf-aig-authorization for a two-key request, cf-aig-gateway-id to select a gateway, or cf-aig-collect-log-payload to control logging for one request. We have not tested Cloudflare AI Gateway with ReadyHermes.