> ## Documentation Index
> Fetch the complete documentation index at: https://docs.laozhang.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Insufficient Balance

> Solutions and preventive measures for insufficient balance issues

## Symptom Description

When calling the API, you receive the following error messages:

```json theme={null}
{
  "error": {
    "message": "Insufficient balance",
    "type": "insufficient_balance",
    "code": "insufficient_balance"
  }
}
```

Or similar prompts:

* "Account balance is insufficient"
* "Please confirm account credit"
* "Balance insufficient, unable to complete request"

## Cause Analysis

### 1. Balance Depleted

Account balance has been completely used up and needs account credit confirmation.

### 2. Insufficient Balance

Account has remaining balance, but insufficient for current request:

* Request token count is too large
* Selected model is expensive
* Single request exceeds budget

### 3. Frozen Balance

Part of balance is frozen and unavailable:

* Pending transactions
* Risk control freezing
* System reservation

### 4. Billing Method Mismatch

Using wrong billing method token:

* Pay-per-use token calling usage-based billing models
* Usage-based billing token calling pay-per-use models

## Solutions

### Immediate Solutions

<Steps>
  <Step title="Check Account Balance">
    1. Log in to [Laozhang API Console](https://api2.laozhang.ai)
    2. Check dashboard balance display
    3. View detailed transaction history
  </Step>

  <Step title="Confirm Account Credit">
    1. Check whether the account has available credit
    2. Confirm billing status with your account owner or support
    3. Wait for account credit update after verification
  </Step>

  <Step title="Verify Account Credit">
    1. Refresh console page
    2. Check if balance has updated
    3. Retry API call
  </Step>
</Steps>

### Emergency Alternatives

If urgent need to continue using:

1. **Switch to Lighter Model**
   ```python theme={null}
   # Original: Using expensive model
   model = "gpt-4-turbo"

   # Alternative: Switch to economical model
   model = "gpt-3.5-turbo"
   ```

2. **Reduce Request Parameters**
   ```python theme={null}
   # Reduce max_tokens
   response = client.chat.completions.create(
       model="gpt-4-turbo",
       max_tokens=500,  # Reduce from 2000 to 500
       messages=[...]
   )
   ```

3. **Use Backup Account**
   * Switch to alternative API key
   * Switch to different service provider

## Preventive Measures

### 1. Set Low Balance Alert

In console set alert threshold:

* **Recommended setting**: 20% of usual daily usage
* **Alert methods**: Email, SMS, webhook
* **Check frequency**: Daily automatic check

### 2. Set Budget Alerts

Configure budget alert rules:

```
Trigger condition: Balance < expected daily usage threshold
Alert method: Email or webhook
Owner: Account administrator
```

### 3. Budget Management

Set usage budget:

* **Daily limit**: Prevent unusual high usage in single day
* **Monthly limit**: Control overall cost
* **Model-specific limit**: Limit expensive model usage

### 4. Monitor Usage

Regularly check usage:

```
Weekly tasks:
- Check balance trend
- Analyze usage distribution
- Identify unusual usage
- Optimize cost structure
```

### 5. Choose Appropriate Billing Method

Choose based on usage pattern:

| Usage Pattern              | Recommended Method  | Reason           |
| -------------------------- | ------------------- | ---------------- |
| **Stable, high-frequency** | Usage-based billing | Lower unit price |
| **Occasional use**         | Pay-per-use         | No waste         |
| **Image/Video generation** | Pay-per-use         | Clear pricing    |
| **Chat applications**      | Usage-based billing | More economical  |

## Balance Management Best Practices

### Budget Allocation

Reasonably allocate budgets:

```
Total monthly budget: $100

Allocation plan:
- Production environment: $60 (60%)
- Development testing: $20 (20%)
- Emergency reserve: $20 (20%)
```

### Cost Optimization

Reduce unnecessary expenses:

1. **Model Selection Optimization**
   ```python theme={null}
   # Simple tasks use economical models
   if task_complexity == "simple":
       model = "gpt-3.5-turbo"
   else:
       model = "gpt-4-turbo"
   ```

2. **Enable Caching**
   ```python theme={null}
   # Cache common requests
   from functools import lru_cache

   @lru_cache(maxsize=100)
   def get_completion(prompt):
       return client.chat.completions.create(...)
   ```

3. **Batch Processing**
   ```python theme={null}
   # Batch process requests to reduce overhead
   results = []
   for batch in chunks(requests, batch_size=10):
       results.extend(process_batch(batch))
   ```

### Usage Tracking

Record and analyze usage:

```python theme={null}
import logging

# Log each API call
logging.info(f"API call: model={model}, tokens={tokens}, cost=${cost}")

# Regularly generate usage reports
def generate_usage_report():
    """Generate weekly usage report"""
    total_cost = sum(costs)
    total_requests = len(costs)
    avg_cost = total_cost / total_requests
    
    print(f"Total cost this week: ${total_cost}")
    print(f"Total requests: {total_requests}")
    print(f"Average cost per request: ${avg_cost}")
```

## Common Questions

<AccordionGroup>
  <Accordion title="How long does account credit take to update?">
    **Account credit update time:**

    * Contract billing: Subject to support and console confirmation
    * Bank transfer: Usually reviewed within 1-3 business days after receipt is provided
    * Invoice or enterprise changes: Subject to account and compliance review

    **If delayed:**

    1. Check payment status
    2. Confirm correct account information
    3. Contact customer support
  </Accordion>

  <Accordion title="Can I get a refund for unused balance?">
    **Refund policy:**

    * Balance can be refunded without violations
    * Refund processing time: 3-7 business days
    * May deduct processing fees (typically 3%-5%)

    **Refund process:**

    1. Submit refund request in console
    2. Provide payment proof
    3. Wait for review
    4. Receive refund
  </Accordion>

  <Accordion title="How to estimate usage costs?">
    **Estimation methods:**

    1. **Token Count Estimation**
       * English: \~1 word = 1.3 tokens
       * Chinese: \~1 character = 2 tokens

    2. **Use Official Pricing Calculator**
       Visit [Pricing Page](/en/pricing) for calculation

    3. **Reference Historical Usage**
       View usage in console

    **Example calculation:**

    ```
    Request: 1000 token prompt
    Response: 2000 token completion
    Model: gpt-4-turbo ($10/M tokens)

    Cost = (1000 + 2000) / 1,000,000 * $10 = $0.03
    ```
  </Accordion>

  <Accordion title="How to prevent accidental high usage?">
    **Prevention measures:**

    1. **Set Rate Limits**
       ```python theme={null}
       from ratelimit import limits, sleep_and_retry

       @sleep_and_retry
       @limits(calls=10, period=60)  # Limit 10 requests per minute
       def call_api():
           return client.chat.completions.create(...)
       ```

    2. **Implement Request Validation**
       ```python theme={null}
       def validate_request(prompt):
           token_count = estimate_tokens(prompt)
           if token_count > 10000:
               raise ValueError("Request too large")
       ```

    3. **Enable Budget Alerts**
       Set daily/weekly/monthly budget alerts

    4. **Code Review**
       Regularly review API call code to prevent loops or repeated calls
  </Accordion>

  <Accordion title="Can I use free tier?">
    **Free Tier Policy:**

    Laozhang API currently does not offer a free tier. To control cost:

    * Use lower-cost models for testing
    * Set token limits and spending alerts
    * Contact support for enterprise pricing if usage is large

    **Cost Reduction Recommendations:**

    1. Use economical models (GPT-3.5 Turbo)
    2. Optimize prompt length
    3. Enable result caching
    4. Batch process requests
  </Accordion>
</AccordionGroup>

## Emergency Contact

If you cannot resolve the issue through above methods, please contact us through:

* **Online Support**: Click chat icon in console
* **Email Support**: [hi@laozhang.ai](mailto:hi@laozhang.ai)
* **Work Hours**: Monday to Friday 9:00-18:00 (UTC+8)
* **Emergency Contact**: For production environment issues, specify "Emergency" in email subject

## Related Resources

* [Pricing Description](/en/pricing) - View detailed pricing
* [Token Management](/en/faq/token-management) - Learn how to manage API tokens
* [Usage Logs](/en/faq/call-logs) - View API usage history
* \[Account Credit Guide]\([https://api2.laozhang.ai/docs/account](https://api2.laozhang.ai/docs/account) credit) - Detailed account credit guide
