1. Check availability
Open the model catalog, select a protocol and configuration, and inspect current Acosmi pricing and availability. If pricing is pending or the configuration is unavailable, wait for it to become ready. This tutorial does not bypass those conditions.
The catalog model ID differs from the profile UUID used as model in these examples. Protocol configurations can have different UUIDs. See the catalog reference.
2. Prepare a key and API balance
Create or retrieve your personal models:chat PAYG key on the key management page. Set ACOSMI_API_KEY securely. Prepare API Credits as directed by the console; a membership subscription does not fund these requests. Never embed the key in browser code.
3. Copy the configuration’s example
Prefer the generated code on the model detail page. This template is for an available V2 OpenAI configuration supporting max_tokens. Fill in the actual profile UUID and current price version. For Anthropic configurations, use the Messages reference.
The V2 example explicitly caps spending at CNY 1 with max_credits="1000000". A V1 total-token example sets an output-token limit, not that spending cap.
: "${ACOSMI_API_KEY:?Set your personal PAYG key}"
: "${ACOSMI_MODEL_ID:?Set a callable V2 OpenAI profile UUID}"
: "${ACOSMI_PRICE_VERSION:?Set its current positive effective_price_version}"
curl --fail-with-body 'https://acosmi.com/v1/chat/completions' \
-H "Authorization: Bearer $ACOSMI_API_KEY" \
-H 'Content-Type: application/json' \
--data-binary @- <<JSON
{"model":"$ACOSMI_MODEL_ID","messages":[{"role":"user","content":"Hello"}],"max_tokens":64,"stream":false,"acosmi_options":{"contract_version":"TEXT_COMPONENTS_V2","expected_price_version":${ACOSMI_PRICE_VERSION},"max_credits":"1000000"}}
JSONOn price changes or an insufficient budget, review the current price/quote and decide whether to continue. Do not automatically raise the cap or repeat a paid POST.
4. Read the response
This example illustrates the protocol shape; it is not a real execution receipt:
{"choices":[{"message":{"role":"assistant","content":"Hello!"},"finish_reason":"stop"}],"usage":{"prompt_tokens":12,"completion_tokens":3,"total_tokens":15}}Read text from choices[].message. For non-2xx responses, inspect the error object. With stream=true, consume streaming events instead of parsing the entire response as JSON.
5. Inspect usage and billing
Retain X-Request-ID and any returned X-Acosmi-Request-Id. Inspect the original request in My requests, Usage, and Billing. Delivery and settlement are separate. A timeout, missing usage or pending reconciliation must not be treated as zero cost.
Tools and structured output · Billing · Separate membership OAuth tutorial