> ## Documentation Index
> Fetch the complete documentation index at: https://docs.useautumn.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Update Balance

> Update a customer balance.

export const DynamicResponseExample = ({json, statusCode = "200"}) => {
  const toCamelCase = str => {
    return str.replace(/_([a-z])/g, (_, c) => c.toUpperCase());
  };
  const convertKeysToCamelCase = obj => {
    if (Array.isArray(obj)) {
      return obj.map(item => convertKeysToCamelCase(item));
    }
    if (obj !== null && typeof obj === "object") {
      return Object.keys(obj).reduce((acc, key) => {
        const camelKey = toCamelCase(key);
        acc[camelKey] = convertKeysToCamelCase(obj[key]);
        return acc;
      }, {});
    }
    return obj;
  };
  const [isTypeScript, setIsTypeScript] = useState(() => {
    if (typeof window !== "undefined") {
      try {
        const lang = localStorage.getItem("code");
        return JSON.parse(lang) === "typescript";
      } catch {
        return true;
      }
    }
    return true;
  });
  useEffect(() => {
    const onMintlifyStorage = event => {
      if (event.detail?.key === "code") {
        try {
          const value = JSON.parse(event.detail.value);
          setIsTypeScript(value === "typescript");
        } catch {}
      }
    };
    const pollInterval = setInterval(() => {
      try {
        const lang = localStorage.getItem("code");
        const value = JSON.parse(lang);
        setIsTypeScript(value === "typescript");
      } catch {}
    }, 300);
    document.addEventListener("mintlify-localstorage", onMintlifyStorage);
    return () => {
      document.removeEventListener("mintlify-localstorage", onMintlifyStorage);
      clearInterval(pollInterval);
    };
  }, []);
  const camelCaseJson = useMemo(() => convertKeysToCamelCase(json), [json]);
  const snakeCaseString = JSON.stringify(json, null, 2);
  const camelCaseString = JSON.stringify(camelCaseJson, null, 2);
  return <ResponseExample>
			{isTypeScript ? <CodeBlock language="json" filename={statusCode}>
					{camelCaseString}
				</CodeBlock> : <CodeBlock language="json" filename={statusCode}>
					{snakeCaseString}
				</CodeBlock>}
		</ResponseExample>;
};

export const DynamicResponseField = ({children, name, ...props}) => {
  const convertToCamelCase = str => {
    if (typeof str !== "string") return str;
    return str.replace(/[_-](\w)/g, (_, c) => c.toUpperCase());
  };
  const [lang, setLang] = useState(() => {
    if (typeof window !== "undefined") {
      const stored = localStorage.getItem("code");
      return stored || '"typescript"';
    }
    return '"typescript"';
  });
  useEffect(() => {
    const onMintlifyStorage = event => {
      const key = event.detail?.key;
      if (key === "code") {
        setLang(event.detail.value);
      }
    };
    const pollInterval = setInterval(() => {
      const current = localStorage.getItem("code");
      if (current && current !== lang) {
        setLang(current);
      }
    }, 500);
    document.addEventListener("mintlify-localstorage", onMintlifyStorage);
    return () => {
      document.removeEventListener("mintlify-localstorage", onMintlifyStorage);
      clearInterval(pollInterval);
    };
  }, [lang]);
  const resolvedName = useMemo(() => {
    try {
      const value = JSON.parse(lang);
      const useCamelCase = value === "typescript";
      return useCamelCase ? convertToCamelCase(name) : name;
    } catch {
      return name;
    }
  }, [name, lang]);
  return <ResponseField name={resolvedName} {...props}>
			{children}
		</ResponseField>;
};

export const DynamicParamField = ({children, body, path, ...props}) => {
  const convertToCamelCase = str => {
    if (typeof str !== "string") return str;
    return str.replace(/[_-](\w)/g, (_, c) => c.toUpperCase());
  };
  const [lang, setLang] = useState(() => {
    if (typeof window !== "undefined") {
      const stored = localStorage.getItem("code");
      return stored || '"typescript"';
    }
    return '"typescript"';
  });
  useEffect(() => {
    const onMintlifyStorage = event => {
      const key = event.detail?.key;
      if (key === "code") {
        setLang(event.detail.value);
      }
    };
    const pollInterval = setInterval(() => {
      const current = localStorage.getItem("code");
      if (current && current !== lang) {
        setLang(current);
      }
    }, 500);
    document.addEventListener("mintlify-localstorage", onMintlifyStorage);
    return () => {
      document.removeEventListener("mintlify-localstorage", onMintlifyStorage);
      clearInterval(pollInterval);
    };
  }, [lang]);
  const resolvedBody = useMemo(() => {
    try {
      const value = JSON.parse(lang);
      const useCamelCase = value === "typescript";
      return useCamelCase ? convertToCamelCase(body) : body;
    } catch {
      return body;
    }
  }, [body, lang]);
  const resolvedPath = useMemo(() => {
    try {
      const value = JSON.parse(lang);
      const useCamelCase = value === "typescript";
      return useCamelCase ? convertToCamelCase(path) : path;
    } catch {
      return path;
    }
  }, [path, lang]);
  return <ParamField body={resolvedBody} path={resolvedPath} {...props}>
			{children}
		</ParamField>;
};

### Body Parameters

<DynamicParamField body="customer_id" type="string" required>
  The ID of the customer.
</DynamicParamField>

<DynamicParamField body="feature_id" type="string" required>
  The ID of the feature.
</DynamicParamField>

<DynamicParamField body="entity_id" type="string">
  The ID of the entity for entity-scoped balances (e.g., per-seat limits).
</DynamicParamField>

<DynamicParamField body="remaining" type="number">
  Set the remaining balance to this exact value. Cannot be combined with add\_to\_balance.
</DynamicParamField>

<DynamicParamField body="add_to_balance" type="number">
  Add this amount to the current balance. Use negative values to subtract. Cannot be combined with current\_balance.
</DynamicParamField>

<DynamicParamField body="usage" type="number">
  The usage amount to update. Cannot be combined with remaining or add\_to\_balance.
</DynamicParamField>

<DynamicParamField body="interval" type="'one_off' | 'minute' | 'hour' | 'day' | 'week' | 'month' | 'quarter' | 'semi_annual' | 'year'">
  Target a specific balance by its reset interval. Use when the customer has multiple balances for the same feature with different reset intervals.
</DynamicParamField>

<DynamicParamField body="included_grant" type="number">
  Set the granted balance to this exact value.
</DynamicParamField>

<DynamicParamField body="balance_id" type="string">
  Target a specific balance by its ID (set on create). Use when the customer has multiple balances for the same feature.
</DynamicParamField>

<DynamicParamField body="next_reset_at" type="number">
  The next reset time for the balance. If there are multiple breakdowns, this will update the breakdown with the next reset time.
</DynamicParamField>

<DynamicParamField body="expires_at" type="number">
  Unix timestamp (milliseconds) when the balance expires. Targets a specific balance via balance\_id / interval when the customer has multiple balances for the same feature.
</DynamicParamField>

### Response

<DynamicResponseField name="success" type="boolean" />


## OpenAPI

````yaml openapi POST /v1/balances.update
openapi: 3.1.0
info:
  title: Autumn API
  version: 2.3.0
servers:
  - url: https://api.useautumn.com
    description: Production server
security:
  - secretKey: []
paths:
  /v1/balances.update:
    post:
      tags:
        - balances
      description: Update a customer balance.
      operationId: updateBalance
      parameters:
        - name: x-api-version
          in: header
          required: true
          schema:
            type: string
            default: 2.3.0
          x-speakeasy-globals-hidden: true
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                customer_id:
                  type: string
                  description: The ID of the customer.
                feature_id:
                  type: string
                  description: The ID of the feature.
                entity_id:
                  type: string
                  description: >-
                    The ID of the entity for entity-scoped balances (e.g.,
                    per-seat limits).
                remaining:
                  type: number
                  description: >-
                    Set the remaining balance to this exact value. Cannot be
                    combined with add_to_balance.
                add_to_balance:
                  type: number
                  description: >-
                    Add this amount to the current balance. Use negative values
                    to subtract. Cannot be combined with current_balance.
                usage:
                  type: number
                  description: >-
                    The usage amount to update. Cannot be combined with
                    remaining or add_to_balance.
                interval:
                  enum:
                    - one_off
                    - minute
                    - hour
                    - day
                    - week
                    - month
                    - quarter
                    - semi_annual
                    - year
                  type: string
                  description: >-
                    Target a specific balance by its reset interval. Use when
                    the customer has multiple balances for the same feature with
                    different reset intervals.
                included_grant:
                  type: number
                  description: Set the granted balance to this exact value.
                balance_id:
                  type: string
                  description: >-
                    Target a specific balance by its ID (set on create). Use
                    when the customer has multiple balances for the same
                    feature.
                next_reset_at:
                  type: number
                  description: >-
                    The next reset time for the balance. If there are multiple
                    breakdowns, this will update the breakdown with the next
                    reset time.
                expires_at:
                  type: number
                  description: >-
                    Unix timestamp (milliseconds) when the balance expires.
                    Targets a specific balance via balance_id / interval when
                    the customer has multiple balances for the same feature.
              required:
                - customer_id
                - feature_id
              title: UpdateBalanceParams
              examples:
                - customer_id: cus_123
                  feature_id: api_calls
                  remaining: 5
            example:
              customer_id: cus_123
              feature_id: api_calls
              remaining: 5
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                required:
                  - success
      x-codeSamples:
        - lang: typescript
          label: Typescript (SDK)
          source: |-
            import { Autumn } from 'autumn-js'

            const autumn = new Autumn()

            const result = await autumn.balances.update({
              customerId: "cus_123",
              featureId: "api_calls",
              remaining: 5,
            });
        - lang: python
          label: Python (SDK)
          source: |-
            from autumn_sdk import Autumn

            autumn = Autumn(secret_key="am_sk_test...")

            res = autumn.balances.update(
                customer_id="cus_123",
                feature_id="api_calls",
                remaining=5,
            )
components:
  securitySchemes:
    secretKey:
      type: http
      scheme: bearer
      bearerFormat: JWT

````