Cap the Lambda worker before you open the queue: reserve a function-level concurrency ceiling, give each SQS event source its own maximum, and make every outbound CometAPI attempt claim one shared job allowance. This keeps a burst from turning into an unpriced burst of model requests. The ceiling controls local admission; it does not prove that a request was accepted, completed, or billed by the provider.

Last reviewed: 2026-11-21 (Asia/Shanghai; 2026-11-20 UTC).

The useful control is a chain of evidence. First choose the maximum number of Lambda invocations that may be in flight. Then choose how many of those invocations each queue may consume. Finally, reserve an attempt and its estimated cost before dispatching a request. If a timeout leaves the outcome uncertain, hold that reservation for reconciliation instead of returning it to the pool.

Start with a per-job concurrency and attempt budget

Write the parent budget before changing an AWS setting. A job should have an application identity, an approved maximum number of provider attempts, input and output limits, a model route, and a stop condition. Keep retries and fallback attempts in the same allowance. A worker that restarts must resume the parent record; it must not receive a fresh allowance simply because its Lambda invocation is new.

For a simple one-request-per-invocation worker, a concurrency ceiling of 12 means at most 12 invocations can be active at once. It does not mean 12 requests per second: throughput also depends on duration, retries, batching, and whether one invocation makes more than one provider call. Record both the maximum in-flight count and the expected attempts per invocation. A conservative planning estimate is:

maximum in-flight provider attempts
  = admitted Lambda invocations
  × provider attempts allowed per invocation

If an invocation can make one initial request and one explicitly approved retry, a ceiling of 12 exposes up to 24 attempts across the active cohort. That is an admission bound, not a billing result. Use the returned usage for completed responses and preserve unresolved attempts until their status is known.

The Step Functions cost ledger describes the same separation between orchestration units and provider attempts. Apply that separation here even when Lambda is the orchestrator: Lambda concurrency, SQS messages, and model usage are different counters.

Set the Lambda ceiling and the SQS ceiling together

AWS documents reserved concurrency as both a minimum and maximum for a function. It can protect downstream resources and costs no extra charge to configure. It also consumes that capacity from the account pool, so a reservation affects other functions. Use a value derived from observed ConcurrentExecutions, the caller deadline, and the provider route’s approved attempt budget. Do not copy the account default as your application limit.

Set the function limit with an environment-supplied name and value:

aws lambda put-function-concurrency \
  --function-name "${FUNCTION_NAME:?Set FUNCTION_NAME}" \
  --reserved-concurrent-executions "${RESERVED_CONCURRENCY:?Set RESERVED_CONCURRENCY}"

Read back the result and retain the returned ReservedConcurrentExecutions with the policy revision. Setting reserved concurrency to zero intentionally pauses processing, which is useful for a controlled stop but creates backlog and retry consequences that must be part of the recovery plan. A lower value can throttle invocations; it does not cancel work already sent to CometAPI.

For an SQS trigger, add the event-source maximum. AWS describes this as an event-source-level setting, independent of reserved concurrency. If a function has several queues, the sum of their maximums should fit inside the function reservation. Setting a queue maximum above the function reservation can cause Lambda to throttle messages. FIFO queues add another ceiling: available message-group IDs can be lower than the configured maximum.

aws lambda update-event-source-mapping \
  --uuid "${EVENT_SOURCE_UUID:?Set EVENT_SOURCE_UUID}" \
  --scaling-config '{"MaximumConcurrency":5}'

The documented SQS range starts at 2 and extends to 1,000 for this setting. Treat those as service limits, not as a recommendation. The queue limit should reflect the approved provider attempt rate, message visibility timeout, function duration, and the amount of retry work that can accumulate. Keep provisioned polling mode separate; AWS says it cannot be combined with the maximum-concurrency option.

Turn provider usage into a reservation

The Lambda cap is only the outer gate. Inside the handler, claim an attempt slot atomically against the parent job before making the network call. Store the job ID, attempt ID, policy revision, model route, input and output ceilings, and reservation state. Release a slot only after a terminal outcome is recorded. A transport timeout after dispatch is an unresolved attempt, not proof of zero cost and not permission to retry immediately.

CometAPI’s chat-completion reference documents bearer authentication, the messages request field, a completion ceiling, and a usage response field. Read the API key from the runtime environment, such as COMETAPI_API_KEY; do not place it in code, logs, or the budget record. For the documented GPT-6 Astra examples, max_completion_tokens covers reasoning and visible output, so a token allowance must include both.

Use a sealed route record so a browser or queue message cannot expand the plan. At admission, check that the selected model, message size, completion ceiling, and attempt number match the approved record. At completion, save the reported usage and the pricing-record version. Keep prompts, completions, credentials, and customer fields out of ordinary cost events.

A practical reservation record has these fields:

FieldDecision it supports
parent job and attempt IDsPrevents a retry from receiving a new budget
Lambda policy revisionBinds the attempt to the concurrency plan in force
maximum attempts and token ceilingsDefines the exposure before dispatch
reservation stateDistinguishes settled, failed, and unresolved work
reported usage and route price versionReconciles the estimate after completion

The ZIP import cost guide shows why a shared parent allowance matters when one input expands into many model requests. Lambda fan-out has the same failure mode even when the input is already in a queue.

Verify throttle, retry, and reconciliation paths

Start in a non-production queue with synthetic messages and a counted provider adapter. Exercise a normal invocation, a concurrency burst, a function error, a queue redelivery, a provider timeout after dispatch, and a response that exceeds the sealed completion ceiling. The adapter should record an attempted call without sending customer prompts.

For each case, require an observable result:

  • A burst reaches the configured function and event-source ceilings; it does not create an unbounded worker wave.
  • A throttled message remains subject to the queue’s documented retry and visibility behavior; the cost record does not call it successful.
  • A provider timeout leaves the attempt unresolved and prevents an automatic duplicate until reconciliation decides what happened.
  • A completed response records usage, the route, and the parent job; missing usage stays unresolved rather than becoming zero.
  • Raising a limit requires a new policy revision, a recalculated attempt allowance, and evidence that the account’s regional quota and downstream route can support it.

AWS lists regional concurrent-execution quotas and a per-function scaling limit, and it notes that new accounts can have reduced quotas. Check the Service Quotas view for the account and Region used by the worker. A successful configuration write is not evidence that the account can sustain the intended workload. Monitor ConcurrentExecutions, throttles, queue age, redeliveries, attempt reservations, unresolved attempts, and provider usage together.

These are acceptance criteria for your environment. No authenticated AWS change, queue run, or CometAPI request was performed for this guide, so the examples describe what to verify rather than reporting a completed deployment.

Make one bounded route decision

Choose one queue and one model route, set a small concurrency ceiling, and reconcile a synthetic burst before increasing it. When that evidence supports an approved request path, Start with CometAPI through the reviewed integration. The same tracked route is also available as the absolute site action . Keep the tracked action tied to this article’s budget record.

Sources checked

Checked on November 21, 2026 (Asia/Shanghai; November 20 UTC). These live official references support the documented service behavior; concurrency values, provider pricing, account quotas, and retry policies remain deployment-specific.