Python SDK for the Koko Finance credit card intelligence API.
Analyze credit card portfolios, compare cards side-by-side, get spending-based recommendations, and check whether a card is worth renewing — all with a few lines of Python.
pip install koko-financefrom koko_finance import KokoClient
client = KokoClient(api_key="koko_your_api_key")
# Analyze your credit card portfolio
analysis = client.analyze_portfolio(
cards=[
{"card_name": "Chase Sapphire Preferred", "annual_fee": 95},
{"card_name": "American Express Gold Card", "annual_fee": 250},
{"card_name": "Citi Double Cash", "annual_fee": 0},
],
spending={"dining": 500, "travel": 300, "groceries": 600, "gas": 150},
primary_goal="travel",
)
print(analysis)| Parameter | Type | Default | Description |
|---|---|---|---|
api_key |
str | required | Your Koko API key (format: koko_xxxxx) |
base_url |
str | https://kokofinance.net |
API base URL |
timeout |
int | 30 |
Request timeout in seconds |
Analyze 1-10 credit cards for total value, per-card verdicts (KEEP/OPTIMIZE/CANCEL), and break-even analysis.
# Fast (default, <100ms) — deterministic calculations
analysis = client.analyze_portfolio(
cards=[
{"card_name": "Chase Sapphire Preferred", "annual_fee": 95},
{"card_name": "American Express Gold Card", "annual_fee": 250},
],
spending={"dining": 500, "travel": 300, "groceries": 400},
primary_goal="travel",
)
# Verbose (3-5s) — adds AI-generated narrative
analysis = client.analyze_portfolio(
cards=[...],
spending={"dining": 500, "travel": 300},
verbose=True,
)Compare 2-3 credit cards side-by-side with fees, rewards, net value, and break-even.
# Fast (default, <100ms) — structured data, no AI winner
comparison = client.compare_cards(
cards=[
{"card_name": "Chase Sapphire Preferred", "annual_fee": 95},
{"card_name": "Capital One Venture X", "annual_fee": 395},
],
spending={"dining": 400, "travel": 500},
primary_goal="travel",
)
# Verbose (3-5s) — adds AI-generated winner and pros/cons
comparison = client.compare_cards(cards=[...], verbose=True)Get the best card recommendations for a spending category.
# From the full market (always fast)
recs = client.recommend_card(
category="dining",
spending={"dining": 600},
credit_tier="excellent",
)
# From your existing portfolio (fast, <100ms)
recs = client.recommend_card(
category="dining",
portfolio_card_names=["Chase Sapphire Preferred", "Citi Double Cash"],
)
# From portfolio with AI narrative (verbose, 2-4s)
recs = client.recommend_card(
category="dining",
portfolio_card_names=["Chase Sapphire Preferred", "Citi Double Cash"],
verbose=True,
)Check if a card is worth keeping at annual fee renewal time.
renewal = client.check_renewal(
card={"card_name": "Chase Sapphire Preferred", "annual_fee": 95},
spending={"dining": 400, "travel": 300},
)
# renewal["verdict"] is "RENEW", "DOWNGRADE", or "CANCEL_AND_REPLACE"Check API health status (no authentication required).
status = client.health()The SDK raises typed exceptions for API errors:
from koko_finance import KokoClient, RateLimitError, AuthenticationError
client = KokoClient(api_key="koko_your_api_key")
try:
result = client.analyze_portfolio(cards=[...])
except AuthenticationError:
print("Invalid API key")
except RateLimitError as e:
print(f"Rate limited. Retry after {e.retry_after} seconds.")| Exception | HTTP Status | When |
|---|---|---|
AuthenticationError |
401 | Invalid or missing API key |
RateLimitError |
429 | Rate limit exceeded (60 req/min) |
ValidationError |
400, 422 | Invalid request parameters |
ServerError |
500 | API server error |
KokoError |
other | Base exception for all API errors |
The spending parameter accepts monthly dollar amounts for these categories:
| Category | Key | Example |
|---|---|---|
| Groceries | groceries |
600 |
| Dining | dining |
400 |
| Travel | travel |
200 |
| Gas | gas |
150 |
| Streaming | streaming |
45 |
| Shopping | shopping |
300 |
| Other | other |
200 |
MIT