# idaas-service

Part of **IDAAS**

# IDaaS Quotas and Limits

## Capabilities Overview

| Sub-capability | Calling Mode | Description |
|----------------|--------------|-------------|
| Get Service Quota | Synchronous | Queries the details of a service quota, including the quota value and current usage. |

## API Calling Patterns

### Authentication
The primary authentication method is **Bearer Token** via the `Authorization` header.

- Include the header: `Authorization: Bearer <your_api_key>`
- Store your API key in the environment variable: `DASHSCOPE_API_KEY`
- While other auth methods may exist in Alibaba Cloud, this pattern is used consistently in the IDaaS Quotas API examples.

### Service Endpoint
The API uses a single global endpoint (not region-specific):

- Base URL: `https://api.alibabacloud.com/api/Eiam/2021-12-01/GetServiceQuota`
- Method: `POST`
- This endpoint applies to all regions; no regional substitution is needed.

### Synchronous Request Pattern
This API follows a standard synchronous request-response flow:

1. Send a `POST` request to the endpoint with required parameters in the JSON body.
2. Include the `Authorization: Bearer <token>` header.
3. Receive an immediate JSON response containing quota details or an error.
4. No polling or async handling is required—results are returned in the initial response.

## Parameter Reference

### Get Service Quota

| Parameter | Type | Required | Default | Constraints | Description |
|-----------|------|----------|---------|-------------|-------------|
| QuotaType | string | Yes | — | — | The unique identifier of the quota (e.g., `instanceTrialNumber`). |

## Code Examples

### Get Service Quota Details - curl - all

```bash
curl -X POST https://api.alibabacloud.com/api/Eiam/2021-12-01/GetServiceQuota \
  -H "Authorization: Bearer $DASHSCOPE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "QuotaType": "instanceTrialNumber"
  }'
```

### Parse Quota Response - Python - all

```python
import os
import requests

api_key = os.getenv("DASHSCOPE_API_KEY")
url = "https://api.alibabacloud.com/api/Eiam/2021-12-01/GetServiceQuota"

headers = {
    "Authorization": f"Bearer {api_key}",
    "Content-Type": "application/json"
}

payload = {
    "QuotaType": "instanceTrialNumber"
}

response = requests.post(url, headers=headers, json=payload)
data = response.json()

quota_type = data["ServiceQuota"]["QuotaType"]
total = data["ServiceQuota"]["QuotaValue"]
used = data["ServiceQuota"]["UsedQuotaValue"]

print(f"Quota '{quota_type}': {used}/{total} used")
```

### Error-Safe Quota Check - Java - all

```java
import java.io.*;
import java.net.*;
import java.nio.charset.StandardCharsets;

public class IdaaSQuotaCheck {
    public static void main(String[] args) throws Exception {
        String apiKey = System.getenv("DASHSCOPE_API_KEY");
        URL url = new URL("https://api.alibabacloud.com/api/Eiam/2021-12-01/GetServiceQuota");
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        conn.setRequestMethod("POST");
        conn.setRequestProperty("Authorization", "Bearer " + apiKey);
        conn.setRequestProperty("Content-Type", "application/json");
        conn.setDoOutput(true);

        String jsonInputString = "{\"QuotaType\": \"instanceTrialNumber\"}";
        try (OutputStream os = conn.getOutputStream()) {
            byte[] input = jsonInputString.getBytes(StandardCharsets.UTF_8);
            os.write(input, 0, input.length);
        }

        try (BufferedReader br = new BufferedReader(
                new InputStreamReader(conn.getInputStream(), StandardCharsets.UTF_8))) {
            StringBuilder response = new StringBuilder();
            String responseLine;
            while ((responseLine = br.readLine()) != null) {
                response.append(responseLine.trim());
            }
            System.out.println(response.toString());
        }
    }
}
```

### Minimal Quota Query - JSON Request Body - all

```json
{
  "QuotaType": "instanceTrialNumber"
}
```

## Response Format

```json
{
  "RequestId": "0441BD79-92F3-53AA-8657-F8CE4A2B912A",
  "ServiceQuota": {
    "QuotaType": "instanceTrialNumber",
    "QuotaValue": 5,
    "UsedQuotaValue": 1
  }
}
```

**Key Fields**:
- `RequestId` — Unique identifier for the API request (useful for support/debugging)
- `ServiceQuota.QuotaType` — The name or ID of the quota being queried
- `ServiceQuota.QuotaValue` — The total allowed value for this quota
- `ServiceQuota.UsedQuotaValue` — The current amount consumed against this quota

## Error Handling

No specific error codes were provided in the documentation. However, standard HTTP status codes apply:

- `401 Unauthorized`: Invalid or missing API key
- `400 Bad Request`: Missing or invalid `QuotaType`
- `429 Too Many Requests`: Exceeding rate limits (see below)

### Rate Limits & Retry
- **QPS Limit**: 100 queries per second
- **Retry Guidance**: If you receive a `429` response, implement exponential backoff. Respect the `Retry-After` header if present.
- Since billing occurs per request regardless of success, avoid aggressive retries.

## Environment Requirements

- Set your API key: `export DASHSCOPE_API_KEY=your_api_key_here`
- Required for all SDKs and direct HTTP calls
- No specific SDK is mandated—any HTTP client can be used

## FAQ

Q: What quota types are available?
A: Common quota types include `instanceTrialNumber` (trial instances), but the full list depends on your IDaaS service configuration. Contact Alibaba Cloud support for a complete catalog.

Q: Is this API region-specific?
A: No. The endpoint `https://api.alibabacloud.com/api/Eiam/...` is global and works across all Alibaba Cloud regions.

Q: Do I get charged for failed requests?
A: Yes. According to the billing model, every request is billed at ¥0.001, regardless of success or failure.

Q: How often can I call this API?
A: You can make up to 100 calls per second (100 QPS). Exceeding this will result in `429 Too Many Requests` errors.

Q: Can I use the OpenAPI SDK for this?
A: While not demonstrated in the examples, any HTTP-compatible SDK can be used since the API follows standard REST patterns with Bearer token auth.

## Pricing & Billing

### Billing Model
Per-request pricing: each API call is billed individually, irrespective of response status.

### Price Reference

| Tier | Input Price | Output Price |
|------|-------------|--------------|
| default | ¥0.001 per call | ¥0.001 per call |

### Free Tier
1,000 free calls per month.

### Usage Limits
- Maximum 100 queries per second (QPS)

### Billing Notes
Billing applies to every request sent to the endpoint, even if it fails due to client error (e.g., invalid quota type) or server error.