Amba

Remote Config

Dynamic configuration values your app fetches at runtime, with stored segment and percentage conditions.

Remote config lets you change app behavior without shipping an update. Set key / value pairs on the server and the SDK fetches them with config.fetch(). Keys can also carry per-segment or percentage-rollout conditions, which apply to signed-in users; a caller without a session gets each key's default value.

How it works

  1. Admins (or AI agents via MCP) set config values on the server. Every value has a type (string, number, boolean, json) and optional stored conditions for specific segments or a percentage of users.
  2. The client SDK fetches the key → value map from GET /v1/client/config. It keeps the last map it fetched on the device, per project and signed-in user, and config.getCached(key, default) reads it with no request: on the next launch the first screen gets the last known values, then the app's shipped configDefaults, then the default passed to the call. See startup values. The response carries Cache-Control: private, max-age=300, so in a browser a repeat config.fetch() within five minutes can return the browser's cached copy.
  3. The route returns an ETag header. A request that sends it back in If-None-Match gets 304 Not Modified while nothing changed, which helps when you call the route yourself. The SDK's fetch() sends no If-None-Match and always receives the full map.
  4. Server-side version hashes make change detection fast: flipping a value bumps config_versions.version_hash, which changes the ETag.

SDK usage

Method signatures:

client.config.fetch(): Promise<ConfigBundle> // { version, values }
client.config.getCached<T>(key: string, defaultValue?: T): T // no request

Read a value on the first frame

Pass the values your app ships with at configure, then read with getCached. It answers at once from the last fetch, the device cache, configDefaults, then your default; the first call also starts a background fetch that refreshes the cache. Every SDK has it (per-platform signatures).

await Amba.configure({
  projectId: 'proj_...',
  clientKey: 'amba_ck_...',
  configDefaults: { daily_limit: 10, feature_paywall_v2: false },
});
 
const limit = Amba.config.getCached('daily_limit', 10);
const paywall = Amba.config.getCached('feature_paywall_v2', false);

Get a single value

const { values } = await client.config.fetch();
const dailyLimit = values['daily_limit'] as number | undefined;
// undefined if the key isn't set

Because each value is typed as unknown, cast to your expected type. Always provide a default:

const limit = ((await client.config.fetch()).values['daily_limit'] as number | undefined) ?? 10;

Get the full config map

const all = (await client.config.fetch()).values;
// { daily_limit: 10, feature_paywall_v2: true, ... }

Refresh

await client.config.fetch();
// Requests the map again (a browser can answer from its cache for up to 5 minutes)

Expo

import { Amba } from '@layers/amba-expo';
 
function SettingsScreen() {
  const [limit, setLimit] = useState<number | null>(null);
  const [paywall, setPaywall] = useState(false);
 
  useEffect(() => {
    (async () => {
      const { values } = await Amba.config.fetch();
      setLimit(typeof values['daily_limit'] === 'number' ? values['daily_limit'] : 10);
      setPaywall(values['feature_paywall_v2'] === true);
    })();
  }, []);
 
  return (
    <View>
      <Text>Daily limit: {limit}</Text>
      {paywall && <PaywallBanner />}
    </View>
  );
}

Amba.config.fetch() returns the full ConfigBundle ({ version, values }); read individual keys off values.

Manual refresh in Expo

await Amba.config.fetch();

Conditional values

A config key can carry conditions that target segments or a percentage of users. GET /v1/client/config evaluates them for a signed-in user, in order, and returns the value of the first condition that matches; a caller without a session gets the default value.

Example schema stored in remote_configs.conditions:

{
  "key": "feature_paywall_v2",
  "value_type": "boolean",
  "default_value": false,
  "conditions": [
    { "segment_id": "seg_power_users", "value": true },
    { "percentage": 25, "value": true }
  ]
}

This stores a default of false with a seg_power_users override and a 25% rollout condition; GET /v1/client/config returns false.

Kill switch

Every key can be switched off without deleting it. A switched-off key (is_active: false) is left out of GET /v1/client/config. The SDK's next successful fetch removes it from the device cache, so config.getCached returns the app's shipped configDefaults value for it, then the caller's default; ship the safe value as the default. Its value, conditions and history stay as they are, and switching it back on serves it again. Switching a key off or on changes the ETag, so an HTTP cache revalidating with If-None-Match gets the new map; the SDK replaces its device cache on its next fetch.

PATCH /v1/admin/projects/:projectId/config/feature_paywall_v2
Authorization: Bearer <developer token>
 
{ "is_active": false }

From an agent, amba_remote_configs_set_active does the same in one call:

amba_remote_configs_set_active({ project_id: "proj_xxx", key: "feature_paywall_v2", active: false })

GET /v1/admin/projects/:projectId/config lists every key with its is_active, so a switched-off key stays visible to you. A scheduled content delivery into a switched-off key writes the new value and leaves the key off.

Change history

Every change to a key is recorded with who made it and what it looked like before and after: creates, updates, deletes, and the kill switch (deactivate / activate). Each entry has action, actor_kind (pat for a developer, server_key, operator, or system for a scheduled content delivery), actor_id, created_at, and before / after snapshots of the value, default value, type, description, conditions, is_active and version. A write that changes nothing records nothing, and a key's history outlives the key.

GET /v1/admin/projects/:projectId/config/feature_paywall_v2/history?limit=20
GET /v1/admin/projects/:projectId/config/history

Both list newest first. limit is 1-200 (default 50); pass the last entry's id as before to read the next page. From an agent: amba_remote_configs_history({ project_id, key? }).

Reading config from server code

A value your server enforces can live in remote config with the rest, segment and percentage rollouts included. A daily rewarded-ad cap is the usual case: the app reads it to show "3 of 5 left", and the function that grants the reward reads the same number to refuse the sixth.

GET /v1/admin/projects/:projectId/config/resolve returns the map Amba.config.fetch() serves a given user. Both routes run the same resolver, so the server and the app always agree: the same segment conditions, the same percentage rollout bucket, the same kill switch, the same value_type coercion.

Query paramRequiredMeaning
app_user_idnoThe app user's id. Omit it for the anonymous view: every key resolves to its default.
{
  "data": { "daily_ad_reward_cap": 8, "feature_paywall_v2": false },
  "meta": {
    "app_user_id": "6f1c2a0e-6c39-4c47-9d0e-2b1b5a7e9c11",
    "matches": {
      "daily_ad_reward_cap": {
        "source": "condition",
        "condition_index": 0,
        "segment_id": "2d7e0b4c-1f7a-4a8e-9a3c-5b0f6e1d2c3a",
        "percentage": null
      },
      "feature_paywall_v2": { "source": "default" }
    }
  }
}

data has the shape the app receives. meta.matches says per key how its value was chosen: default, or condition with the winning entry's position in conditions, its segment_id and its percentage. A key switched off with the kill switch is absent from both, as it is for the app.

An app_user_id that names no user in the project returns 404 USER_NOT_FOUND, so a wrong id fails loudly in code that enforces a limit. A value that is not a UUID returns 400 INVALID_INPUT.

Resolution depends on who the user is: their segment memberships and their rollout bucket. Device details such as platform, app version and locale reach it through segments (a segment can target app_version or OS), so the route takes no device parameters.

In an Amba function, call it with the project-scoped token every function receives:

export default {
  async fetch(req: Request, env: Env): Promise<Response> {
    const { app_user_id } = (await req.json()) as { app_user_id: string };
 
    const res = await fetch(
      `${env.AMBA_API_URL}/v1/admin/projects/${env.AMBA_PROJECT_ID}/config/resolve?app_user_id=${encodeURIComponent(app_user_id)}`,
      { headers: { Authorization: `Bearer ${env.AMBA_INTERNAL_TOKEN}` } },
    );
    if (!res.ok) return Response.json({ error: 'config unavailable' }, { status: 502 });
    const { data } = (await res.json()) as { data: Record<string, unknown> };
 
    const cap = typeof data.daily_ad_reward_cap === 'number' ? data.daily_ad_reward_cap : 5;
    // ...count today's rewards for app_user_id and refuse once it reaches `cap`
    return Response.json({ cap });
  },
};
 
interface Env {
  AMBA_API_URL: string;
  AMBA_PROJECT_ID: string;
  AMBA_INTERNAL_TOKEN: string;
}

From an agent: amba_remote_configs_resolve({ project_id, app_user_id? }) shows what one user is served, which is also the quickest way to check a targeting rule.

Setting config values

Via the Admin API

POST /v1/admin/projects/:projectId/config
Authorization: Bearer <developer token>
 
{
  "key": "daily_limit",
  "value": 10,
  "value_type": "number",
  "description": "Maximum daily actions allowed"
}

Via MCP

Agent: Add the new onboarding flag, off by default, with a stored 10% rollout condition.

amba_remote_configs_create({
  project_id: "proj_xxx",
  key: "feature_onboarding_v2",
  value: false,
  value_type: "boolean",
  description: "New onboarding experience",
  conditions: [{ percentage: 10, value: true }]
})

Via the CLI

amba config set daily_limit 10
amba config set feature_paywall_v2 true
amba config list

Routes reference

MethodPathDescription
GET/v1/client/configFetch config values. Supports If-None-Match → 304.
POST/v1/admin/projects/:projectId/configCreate or update a config value
GET/v1/admin/projects/:projectId/configList every key with its is_active
PATCH/v1/admin/projects/:projectId/config/:keyUpdate a key, including is_active (kill switch)
DELETE/v1/admin/projects/:projectId/config/:keyDelete a config value
GET/v1/admin/projects/:projectId/config/historyChange history for the whole project
GET/v1/admin/projects/:projectId/config/:key/historyChange history for one key
GET/v1/admin/projects/:projectId/config/resolveThe values one app user is served, for server code

MCP tools

ToolDescription
amba_remote_configs_listList a project's config keys (values, types, conditions)
amba_remote_configs_createCreate / upsert a key with optional conditions
amba_remote_configs_updatePartially update a single key (only fields provided)
amba_remote_configs_set_activeKill switch: switch a key off or back on
amba_remote_configs_historyWho changed which key and when, with before / after
amba_remote_configs_resolveThe values one app user is served, and which rule matched
amba_remote_configs_deleteRemove a key

On this page