Hosting · Services

Services

Services let apps call outside providers, such as AI models and podcast search, through a user's Civility account. You manage them in /admin/services. This page covers how to let the server make those calls, how to provide your own keys, and how to cap their use.

How a call can be made

Each service supports one or more of these modes.

Mode Who makes the call Whose key is used
client-direct The user's browser The user's
server-proxy Your server The user's, or none if the service needs no key
bundle Your server Yours (a "bundle credential")

Built-in services

civ api start registers these services.

Service Modes Key
ai.claude client-direct, server-proxy, bundle API key
ai.openai client-direct, server-proxy, bundle API key
ai.gemini server-proxy, bundle API key
podcast.podcastindex server-proxy, bundle Podcast Index key and secret
podcast.rssfetch server-proxy None
ai.local-proxy server-proxy Optional

Default state

On a new server:

  • The list of services is served at /api/v1/services.
  • The server makes no outbound calls. Only client-direct calls work, with the user's own key.
  • No bundle credentials are stored.

These settings are stored in the database. civ api start reads no service keys or switches from the environment.

Let the server make calls

  1. Open /admin/services.
  2. Under Service proxy, tick Allow service proxying and save.

This turns on both server-proxy and bundle calls, with no restart. Turning it off blocks both, even if a bundle credential is stored. It does not affect client-direct calls.

After this, podcast.rssfetch works for every user, because it needs no key. Other services work for users who have saved their own key in an app.

Your firewall must allow outbound connections to the providers. The server refuses to call private, loopback and link-local addresses, only uses http and https, and does not follow redirects. The one exception is described in Allow a service to reach your private network.

Provide your own key

A bundle credential is a provider key that you pay for. Users without a key of their own can then use the service.

  1. Turn on Allow service proxying, as above. Saving a credential does not turn it on.

  2. In /admin/services, under Set / rotate a bundle credential, choose the service.

  3. Enter the secret, one key=value per line.

    For ai.claude, ai.openai and ai.gemini:

    key=YOUR_API_KEY
    

    For podcast.podcastindex:

    key=YOUR_PODCAST_INDEX_KEY
    secret=YOUR_PODCAST_INDEX_SECRET
    
  4. Optionally fill in Limits. See Limit what a key can spend. The Metadata field is optional JSON for settings that are not secret, such as a region.

  5. Click Save credential.

The credential works right away. To replace a key, save a new one for the same service. To remove it, click Delete in the service's row.

Secrets are encrypted with CIVILITY_AUTH_SECRET. The panel shows the names of the stored fields, never their values.

Podcast Index does not allow calls from a browser, so podcast.podcastindex only works when proxying is on.

Limit what a key can spend

The Limits field takes a JSON object. Every field is optional.

{
  "models": ["model-a", "model-b"],
  "maxOutputTokens": 4096,
  "maxInputBytes": 262144,
  "pricing": { "model-a": { "input": 3, "output": 15 } },
  "monthlyBudgetUsd": 50
}
Field Meaning
models The models apps may use with this key. If empty or left out, only the service's default model is allowed.
maxOutputTokens The most output tokens per call.
maxInputBytes The largest input per call, in bytes. Default: 1 MB.
pricing The price of each model in US dollars per million tokens, as input and output.
monthlyBudgetUsd The most this key may spend per calendar month, across all users. Calls are refused once it is reached.

When monthlyBudgetUsd is set, a call for a model with no entry in pricing is refused.

Limit calls per user

Bundle calls count against a monthly allowance for each user. There are two caps, and a call must fit within both:

  • Bundle calls per user per month, for all services together. The default is 0, which means no limit.
  • Per-service monthly bundle allowances, for one service.

Set both in /admin/limits. A tier or a per-user override can set different values. To set one user's allowance, use PATCH /admin/users/:id/limits with maxBundleInvocationsPerMonth.

When a user reaches a cap, the call fails with services.quota_exceeded (HTTP 429). Calls made with the user's own key are never counted.

Turn a service off or limit its modes

Each row in /admin/services has an Allowed modes form.

Choice Effect
Use the service defaults The service uses the modes listed in Built-in services.
Disabled The server refuses all calls to the service. Stored credentials and user grants are kept.
Use selected modes Only the ticked modes are allowed. Tick at least one. You can only tick modes the service supports.

Changes apply right away. server-proxy and bundle still need Allow service proxying.

Disabling a service stops calls through your server. It cannot stop an app from calling a provider directly.

An app that has already loaded the service list may need a reload to see a change. The server checks the current setting on every call.

Allow a service to reach your private network

Some services are built to call a server on the same machine or on your private network. The example is ai.local-proxy, which relays to a self-hosted model server at http://localhost:11434 by default. civ api start registers it with that default address. A different address needs a server built from source.

Such a service fails with services.egress_denied until you allow it:

  1. Turn on Allow service proxying, as above.
  2. In /admin/services, under Private-network access, tick Allow calls to loopback and private addresses for the service and save.

The change applies right away and is recorded in the audit log. The setting is off by default and is separate for each service. The section only lists services that declare a private-network upstream. No other service can be given this access.

Risk. While this is on, every user whose app is granted the service can send requests through your server to the address the service is configured with. Users cannot choose the address, but anything that upstream offers is open to them. Allow it only for an upstream you mean to share with your users.

Even when allowed, the server still refuses link-local addresses (including cloud metadata endpoints such as 169.254.169.254), only uses http and https, and does not follow redirects.

Read the services table

The Server access column shows how the server can reach each service now:

Value Meaning
Host bundle key available A bundle credential is stored and bundle calls are allowed.
Requires a user-owned key The server relays calls for users who saved their own key.
Available without a key The service needs no key.
Proxy disabled Allow service proxying is off.
Disabled The service is turned off in Allowed modes.

Rate limit

Services marked as rate-limited share one serviceProxy rate limit per user: 20 calls per 5 minutes by default. Of the built-in services, this applies to podcast.rssfetch. Change it in /admin/limits.

What to turn on

You want Do this
No outbound calls from your server Nothing. This is the default.
Users bring their own keys, your server relays Turn on Allow service proxying.
Users reach a model server you run locally Turn on proxying, and allow ai.local-proxy under Private-network access.
You provide the keys, with a cap Turn on proxying, save a bundle credential, and set an allowance in /admin/limits or a budget in Limits.
You provide the keys, with no cap Turn on proxying and save a bundle credential. Leave the allowances at 0.

See also