Catatan Harian Mas Andri

Silahkan digunakan dengan bijaksana

back

Cara Mudah Cek Kompatibilitas API Key Google AI dengan Tool Python

26 Mei 2025 || 06:26:49 WIB || ClassyID

 


Pendahuluan

Pernah bingung kenapa API key Google AI Anda tidak bisa akses model tertentu? Atau penasaran model mana saja yang bisa dipakai tanpa setup billing?

Google AI punya banyak model keren seperti Gemini 2.5, Imagen 3, dan Veo 2. Tapi sayangnya, tidak semua model gratis dan beberapa punya persyaratan khusus.

Artikel ini akan membahas tool Python yang saya buat untuk mengecek kompatibilitas API key dengan berbagai model Google AI secara otomatis. Tool ini bisa mendeteksi:

Mengapa Tool Ini Penting?

Problem yang Sering Dihadapi Developer

  1. Trial and Error - Coba satu-satu model sampai ketemu yang work
  2. Error Messages Confusing - Pesan error kadang tidak jelas
  3. Documentation Scattered - Info model tersebar di berbagai halaman
  4. Billing Surprise - Tiba-tiba kena charge karena tidak tahu model berbayar

Solusi yang Ditawarkan

Tool Gemini API Model Checker ini menyelesaikan semua masalah di atas dengan:

 Fitur Utama Tool

1. Quick Check Mode 

Mode cepat yang test 5 model paling populer:

2. Comprehensive Check Mode 

Mode lengkap yang test semua model dalam kategori:

3. Smart Error Detection 

Tool bisa membedakan jenis error:

4. Detailed Reporting 

Generate laporan lengkap dengan:

Cara Install dan Setup

Step 1: Persiapan Environment

# Install Python dependencies
pip install google-genai>=1.10.0

# Clone atau download script
git clone https://github.com/username/gemini-api-model-checker.git
cd gemini-api-model-checker

Step 2: Dapatkan API Key

  1. Buka Google AI Studio
  2. Login dengan akun Google
  3. Klik "Create API key"
  4. Copy API key yang dihasilkan

Step 3: Setup API Key di Script

Edit file api_model_checker.py:

# Ganti dengan API key Anda
os.environ['GOOGLE_API_KEY'] = ""

Penting: Jangan commit API key ke public repository!

Cara Penggunaan

Jalankan Script

python api_model_checker.py

Pilih Mode Testing

GOOGLE AI API KEY MODEL CHECKER
==================================================
Select testing mode:
1. Quick check (popular models only)
2. Comprehensive check (all models)
Choose (1/2): 

Rekomendasi:

Memahami Output Tool

Sample Output Quick Check

QUICK CHECK: POPULAR MODELS
========================================
gemini-1.5-flash
   Most common free text model
   AVAILABLE

gemini-2.0-flash
   Latest multimodal model
   QUOTA LIMITED

imagen-3.0-generate-002
   Latest image generation
   NEEDS BILLING

veo-2.0-generate-001
   Latest video generation
   NEEDS BILLING

gemini-2.5-pro-preview-05-06
   Most advanced reasoning
   NEEDS BILLING

QUICK SUMMARY:
Available: 1
Need billing: 3
Quota limited: 1

TIP: Setup GCP billing to access premium models
   → https://console.cloud.google.com/billing

Interpretasi Status

Status Artinya Action yang Perlu Dilakukan
AVAILABLE Model siap pakai Langsung bisa coding!
NEEDS BILLING Perlu setup billing GCP Setup billing, dapat $300 credit
QUOTA LIMITED Kena rate limit Tunggu 24 jam atau setup billing
ERROR Ada masalah teknis Cek API key atau koneksi

Setup Billing GCP (Opsional tapi Recommended)

Jika banyak model yang status NEEDS BILLING, ikuti langkah ini:

Step 1: Buka Google Cloud Console

Step 2: Create Billing Account

Step 3: Link Project ke Billing

Step 4: Enable APIs

Estimasi Biaya:

Customization dan Pengembangan

Tambah Model Baru

Jika ada model baru yang ingin ditest, edit bagian ini:

def check_text_models(client):
    text_models = [
        # Tambah model baru di sini
        "gemini-3.0-ultra",  # contoh
        # Model existing...
        "gemini-2.5-flash-preview-05-20",
    ]

Ubah Rate Limiting

Jika sering kena quota, tambah delay:

time.sleep(2)  # Ubah dari 1 detik ke 2 detik

Custom Report Format

Edit fungsi generate_report() untuk format laporan sesuai kebutuhan.

Troubleshooting Common Issues

Issue 1: "Basic Connection Failed"

Penyebab: API key salah atau expired
Solusi:

Issue 2: "All Models Need Billing"

Penyebab: Akun belum setup billing
Solusi:

Issue 3: "Quota Exhausted di Semua Model"

Penyebab: Daily quota habis
Solusi:

Issue 4: Script Hanging/Stuck

Penyebab: Network timeout atau server Google busy
Solusi:

Tips Optimasi Penggunaan

1. Mulai dengan Quick Check

Selalu jalankan quick check dulu sebelum comprehensive check untuk save quota.

2. Save Report untuk Reference

Tool otomatis save report dengan timestamp. Simpan untuk tracking compatibility over time.

3. Use Environment Variables

Untuk production, gunakan environment variable:

export GOOGLE_API_KEY="your_key_here"
python api_model_checker.py

4. Batch Testing

Jika punya multiple API keys, buat script wrapper untuk test semua sekaligus.

5. Monitor Quota Usage

Check Google Cloud Console regularly untuk monitor usage dan billing.

Roadmap dan Future Development

Tool ini bisa dikembangkan lebih lanjut dengan fitur:

Use Cases di Real World

1. Developer Onboarding

Tim baru bisa langsung tahu model mana yang accessible tanpa trial-error.

2. Project Planning

PM bisa estimate budget berdasarkan model requirements.

3. Cost Optimization

Identify free alternatives sebelum pakai model premium.

4. Debugging Production Issues

Quickly check jika production error karena model compatibility.

5. API Migration

Compare compatibility sebelum migrate ke API key atau project baru.

Kesimpulan

Tool Gemini API Model Checker ini sangat membantu developer yang work dengan Google AI API. Dengan tool ini, Anda bisa:

Next Steps:

  1. Download dan jalankan tool ini
  2. Setup billing jika perlu akses model premium
  3. Start building amazing AI applications!

Tool ini open source dan bisa dikustomisasi sesuai kebutuhan. Jangan lupa star repository-nya jika membantu!