5-minute quickstart
1. Set environment variables
Create an API key in the customer portal and inject it into your local environment. Never put a key in source code, shell history, logs, or screenshots. An AICredits API Key is only for the AI Credits data API; it is not an official key issued by another model service.
export AICREDITS_API_KEY="inject from a secure source"
export API_BASE_URL="data API origin"
export MODEL="choose a value returned by /v1/models"The data API uses Authorization: Bearer $AICREDITS_API_KEY. Check the public catalog for openai_chat_completions, then call /v1/models to confirm accessible model IDs before running an example. /v1/models itself does not return protocol details.
2. Send a request
cURL
#!/usr/bin/env bash
set -euo pipefail
: "${AICREDITS_API_KEY:?Set AICREDITS_API_KEY in your environment}"
: "${API_BASE_URL:?Set API_BASE_URL to the data API origin}"
: "${MODEL:?Set MODEL to a model listed by /v1/models}"
curl --fail-with-body --silent --show-error \
"${API_BASE_URL}/v1/chat/completions" \
-H "Authorization: Bearer $AICREDITS_API_KEY" \
-H "Content-Type: application/json" \
--data "{\"model\":\"${MODEL}\",\"messages\":[{\"role\":\"user\",\"content\":\"<YOUR_PROMPT>\"}]}"Python standard library
import json
import os
import urllib.request
api_key = os.environ["AICREDITS_API_KEY"]
base_url = os.environ["API_BASE_URL"].rstrip("/")
model = os.environ["MODEL"]
body = json.dumps({
"model": model,
"messages": [{"role": "user", "content": "<YOUR_PROMPT>"}],
}).encode()
request = urllib.request.Request(
f"{base_url}/v1/chat/completions",
data=body,
headers={"Authorization": f"Bearer {api_key}", "Content-Type": "application/json"},
method="POST",
)
with urllib.request.urlopen(request, timeout=30) as response:
print(response.read().decode())Node.js 18+
const apiKey = process.env.AICREDITS_API_KEY
const baseURL = process.env.API_BASE_URL?.replace(/\/$/, '')
const model = process.env.MODEL
if (!apiKey || !baseURL || !model) {
throw new Error('Set AICREDITS_API_KEY, API_BASE_URL, and MODEL in the environment')
}
const response = await fetch(`${baseURL}/v1/chat/completions`, {
method: 'POST',
headers: { Authorization: `Bearer ${apiKey}`, 'Content-Type': 'application/json' },
body: JSON.stringify({
model,
messages: [{ role: 'user', content: '<YOUR_PROMPT>' }],
}),
signal: AbortSignal.timeout(30_000),
})
if (!response.ok) throw new Error(`Request failed with HTTP ${response.status}`)
console.log(await response.json())3. Inspect the result
Retain the X-Request-Id response header for troubleshooting, but do not log request or response bodies. Use /v1/balance for available balance and /v1/usage for aggregate usage in the current credential scope.
Next: protocol and SDK support · authentication and key safety · error handling
4. Token counting and embeddings
These public operations are live, and the model must still come from /v1/models. /v1/messages/count_tokens supports enabled OpenAI, Grok, and Claude paths. Grok counting is a local estimate and does not determine final billable usage. Embeddings models must declare the openai_embeddings protocol.
Messages token counting
#!/usr/bin/env bash
set -euo pipefail
: "${AICREDITS_API_KEY:?Set AICREDITS_API_KEY in your environment}"
: "${API_BASE_URL:?Set API_BASE_URL to the data API origin}"
: "${MODEL:?Set MODEL to a listed model with Messages token counting}"
curl --fail-with-body --silent --show-error \
"${API_BASE_URL}/v1/messages/count_tokens" \
-H "x-api-key: $AICREDITS_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "Content-Type: application/json" \
--data "{\"model\":\"${MODEL}\",\"messages\":[{\"role\":\"user\",\"content\":\"<TEXT_TO_COUNT>\"}]}"Embeddings
#!/usr/bin/env bash
set -euo pipefail
: "${AICREDITS_API_KEY:?Set AICREDITS_API_KEY in your environment}"
: "${API_BASE_URL:?Set API_BASE_URL to the data API origin}"
: "${MODEL:?Set MODEL to a model listed by /v1/models with openai_embeddings support}"
curl --fail-with-body --silent --show-error \
"${API_BASE_URL}/v1/embeddings" \
-H "Authorization: Bearer $AICREDITS_API_KEY" \
-H "Content-Type: application/json" \
--data "{\"model\":\"${MODEL}\",\"input\":\"<TEXT_TO_EMBED>\"}"5. More integration options
Use Responses / OpenAI-compatible Claude calls, Messages, native Gemini, or the TypeScript / Swift / Kotlin SDK 0.3.0. See protocol support for image/video request shapes and limits.
Connect Chinese models
DeepSeek, Kimi, MiniMax and Zhipu GLM use the same platform credentials. Follow the Chinese model guide to select published protocols and authorized IDs. GLM has no Responses path; use its implemented Chat or Messages interfaces. SDK 0.3.0 listPublicModels reads public capabilities and rates.