Introduction
As AI agent factories and automated workflows become more sophisticated, not every inference task requires immediate interactive streaming. Generating weekly summaries, categorizing document archives, running batch evaluations, or pre-computing embeddings can easily be processed asynchronously in the background.
To make bulk AI processing cost-effective and scalable, Lynio AI Gateway offers an asynchronous batch processing API. Batch jobs run on available GPU compute nodes during quiet cluster windows and receive steep credit discounts—ranging from 40% to 60% off standard token prices—while interactive users retain full priority preemption.
In this tutorial, you will learn how to:
- Authenticate using a Key-ID and Secret with
curlto obtain a temporary Bearer Token. - Query available regional AI models and their credit multipliers.
- Submit an asynchronous AI batch job with custom priority and discount levels.
- Poll the status, extract reasoning traces, and retrieve the finished output.
- Inspect your tenant's credit usage and monthly token quota.
Step 1: Obtain a Bearer Authorization Token
Lynio IAM supports machine-to-machine authentication using API Keys. When you create an API Key in the Console > Identity & Access Management > Applications tab (or via the API), you are issued:
- Key-ID (
client_id): Starts withlk_... - Key Secret (
client_secret): Starts withlks_...(shown only once upon creation)
You can exchange your Key-ID and Secret for a signed JWT Bearer Token using the OAuth2 Client Credentials flow.
Requesting the Token with cURL
Run the following command in your terminal, replacing the placeholders with your credentials:
# Set your API Key credentials
export LYNIO_KEY_ID="lk_your_key_id_here"
export LYNIO_KEY_SECRET="lks_your_secret_key_here"
# Request a Bearer token
curl -s -X POST "https://iam.lynio.cloud/oauth2/token" \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "grant_type=client_credentials" \
-d "client_id=${LYNIO_KEY_ID}" \
-d "client_secret=${LYNIO_KEY_SECRET}"
Sample Response
Lynio IAM returns a JSON object containing your access_token and its expiration window:
{
"access_token": "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6...",
"token_type": "Bearer",
"expires_in": 3600,
"scope": "openid profile email"
}
Exporting the Bearer Token
For the rest of this tutorial, store the access token in an environment variable for seamless reuse:
export LYNIO_TOKEN="eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6..."
export LYNIO_API_URL="https://api.lynio.cloud/api/v1/ai"
TIP
Bearer tokens issued by Lynio IAM are valid for 1 hour (3,600 seconds). For long-running daemons, automate the token renewal when the token approaches expiration.
Step 2: Discover Available Regional AI Models
Every sovereign European region on Lynio Cloud hosts its own optimized cluster of GPU-accelerated models (e.g. llama3.3:70b, deepseek-r1:32b, qwen2.5-coder:32b, mistral-small:24b). Each model has an associated Credit Multiplier reflecting its compute complexity and VRAM footprint.
To discover the models currently available in your region, send an authenticated GET request:
curl -s -X GET "${LYNIO_API_URL}/models" \
-H "Authorization: Bearer ${LYNIO_TOKEN}" \
-H "Content-Type: application/json"
Sample Response
{
"object": "list",
"data": [
{
"id": "qwen3.5:2b",
"object": "model",
"created": 1787126415,
"owned_by": "ollama",
"credit_multiplier": 1
},
{
"id": "gemma4:e2b",
"object": "model",
"created": 1787126415,
"owned_by": "ollama",
"credit_multiplier": 1
}
]
}
Choose the model tag (e.g. gemma4:e2b) that best matches your workload.
Step 3: Create an Asynchronous AI Batch Job
Batch jobs are queued and executed asynchronously in the background. Lynio offers three priority tiers with dynamic discount pricing:
| Priority Level | Priority Value | Discount | Credit Multiplier Factor | Ideal Use Case |
|---|---|---|---|---|
| Low | 0 | 60% OFF | Overnight batches, large bulk document processing. | |
| Normal (Default) | 10 | 50% OFF | Standard background tasks, scheduled reports. | |
| High | 20 | 40% OFF | Time-sensitive batch jobs with 3x higher dispatch weight. |
NOTE
Fair Queueing: When queues contain mixed priorities, Lynio's Weighted Fair Queueing (WFQ) dispatcher processes tasks in a balanced 3 High : 2 Normal : 1 Low ratio. Lower priority jobs will never be starved.
Submitting a Batch Job with cURL
Submit a new batch inference request using POST /jobs:
curl -s -X POST "${LYNIO_API_URL}/jobs" \
-H "Authorization: Bearer ${LYNIO_TOKEN}" \
-H "Content-Type: application/json" \
-d '{
"model": "gemma4:e2b",
"prompt": "Analyze the architectural advantages of sovereign federated cloud computing for European healthcare providers. Provide 3 concrete examples.",
"system_prompt": "You are a senior enterprise cloud architect. Provide concise, structured, and technical insights.",
"temperature": 0.7,
"priority": 0
}'
Sample Response (HTTP 202 Accepted)
The API immediately validates your quota, records the job in the queue, and returns an HTTP 202 Accepted response with your unique job ID:
{
"id": "8f3b610c-5182-4521-a3f2-1b8f047522ee",
"status": "queued",
"model": "gemma4:e2b",
"priority": 0,
"batch_discount": 0.4,
"created_at": "2026-08-17T20:15:00.123456Z"
}
Save the returned id to check its progress.
Step 4: Poll Job Status & Retrieve the Output
While your job is queued or processing on a GPU node, you can query its status at any time via GET /jobs/<JOB_ID>:
export JOB_ID="8f3b610c-5182-4521-a3f2-1b8f047522ee"
curl -s -X GET "${LYNIO_API_URL}/jobs/${JOB_ID}" \
-H "Authorization: Bearer ${LYNIO_TOKEN}"
Response Lifecycle
- Queued: The task is waiting in line according to its weighted fair priority.
- Processing: An idle GPU slot was allocated and inference is running.
- Completed: The inference completed successfully.
Sample Completed Response
{
"id": "8f3b610c-5182-4521-a3f2-1b8f047522ee",
"status": "completed",
"model": "gemma4:e2b",
"region": "NL-Lynio-MSP1",
"priority": 0,
"batch_discount": 0.4,
"prompt_tokens": 58,
"completion_tokens": 420,
"total_tokens": 478,
"model_multiplier": 1.0,
"total_credits": 191,
"duration_ms": 4120,
"response": {
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "Sovereign federated cloud computing provides healthcare institutions with verifiable data locality, GDPR compliance, and resilience against foreign jurisdictional overreach...",
"reasoning_content": "The user is asking for architectural advantages in healthcare. Key points: 1. Strict GDPR & health data isolation; 2. Sovereign encryption KMS; 3. Low latency local MSP nodes..."
},
"finish_reason": "stop"
}
]
},
"created_at": "2026-08-17T20:15:00.123456Z",
"started_at": "2026-08-17T20:15:01.050000Z",
"completed_at": "2026-08-17T20:15:05.170000Z"
}
Notice the Credit Savings:
- Total Raw Tokens: 478
- Model Multiplier: 1.0x
- Standard Cost: 478 Credits
- With Low Priority Batch Discount (60% OFF / Factor 0.40):
NOTE
Zero-Charge Guarantee: If a background batch job fails or is aborted due to a network interruption, 0 credits are deducted from your balance.
Step 5: Check Your Tenant Credit Status & Quota
You can monitor your monthly AI credit consumption, pacing limits, and remaining allowance with GET /usage:
curl -s -X GET "${LYNIO_API_URL}/usage" \
-H "Authorization: Bearer ${LYNIO_TOKEN}"
Sample Response
{
"tenant_id": "ten_9b4a123f",
"tenant_name": "Acme Health B.V.",
"monthly_quota": 1000000,
"used_tokens_month": 142850,
"remaining_tokens": 857150,
"total_prompt_tokens": 45200,
"total_completion_tokens": 97650,
"usage_percentage": 14.28,
"active_jobs_count": 0,
"pacing_limits": {
"five_hour_burst_limit": 100000,
"five_hour_used": 12400,
"weekly_pacing_limit": 350000,
"weekly_used": 68500
}
}
All-in-One Automation Script
Here is a complete, production-ready bash script that ties everything together. It authenticates, queries models, submits a batch job, polls until completion, and outputs the result:
#!/usr/bin/env bash
set -euo pipefail
# Configuration
LYNIO_KEY_ID="${LYNIO_KEY_ID:-lk_your_key_id}"
LYNIO_KEY_SECRET="${LYNIO_KEY_SECRET:-lks_your_secret_key}"
API_BASE="https://api.lynio.cloud/api/v1/ai"
IAM_BASE="https://iam.lynio.cloud/oauth2/token"
echo "==> 1. Authenticating with Lynio IAM..."
TOKEN_RES=$(curl -s -X POST "$IAM_BASE" \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "grant_type=client_credentials" \
-d "client_id=${LYNIO_KEY_ID}" \
-d "client_secret=${LYNIO_KEY_SECRET}")
TOKEN=$(echo "$TOKEN_RES" | grep -o '"access_token":"[^"]*' | cut -d'"' -f4)
if [ -z "$TOKEN" ]; then
echo "Error: Failed to obtain access token."
echo "$TOKEN_RES"
exit 1
fi
echo "✓ Bearer token acquired successfully."
echo "==> 2. Submitting AI Batch Job (60% Discount)..."
JOB_RES=$(curl -s -X POST "${API_BASE}/jobs" \
-H "Authorization: Bearer ${TOKEN}" \
-H "Content-Type: application/json" \
-d '{
"model": "gemma4:e2b",
"prompt": "Explain the concept of GPU Least-Connections scheduling in 2 concise sentences.",
"priority": 0
}')
JOB_ID=$(echo "$JOB_RES" | grep -o '"id":"[^"]*' | cut -d'"' -f4)
echo "✓ Batch Job Created: ID = $JOB_ID"
echo "==> 3. Polling for completion..."
while true; do
STATUS_RES=$(curl -s -X GET "${API_BASE}/jobs/${JOB_ID}" \
-H "Authorization: Bearer ${TOKEN}")
STATUS=$(echo "$STATUS_RES" | grep -o '"status":"[^"]*' | cut -d'"' -f4)
echo " Current Status: $STATUS"
if [ "$STATUS" == "completed" ] || [ "$STATUS" == "failed" ]; then
break
fi
sleep 2
done
if [ "$STATUS" == "completed" ]; then
echo ""
echo "==================== RESULT ===================="
echo "$STATUS_RES" | jq '.response_payload.choices[0].message.content'
echo "================================================"
echo "Tokens Used: $(echo "$STATUS_RES" | jq '.total_tokens')"
echo "Discounted Credits Charged: $(echo "$STATUS_RES" | jq '.total_credits')"
else
echo "Job failed: $(echo "$STATUS_RES" | jq '.error_message')"
fi
echo ""
echo "==> 4. Checking updated monthly credit usage..."
curl -s -X GET "${API_BASE}/usage" \
-H "Authorization: Bearer ${TOKEN}" | jq '{used_credits, remaining_credits, usage_percentage}'
Conclusion
With Lynio AI Gateway's batch processing API, you can run large-scale AI automation pipelines while cutting compute expenses by up to 60%. Whether you integrate via curl, Python, Node.js, or an external AI agent framework, the asynchronous endpoints give you predictable costs, guaranteed data sovereignty, and reliable GPU scheduling.
To explore interactive prompting or monitor your background jobs visually, visit the AI Playground in the LYNIO Web Console.