Skip to content

About

Automated Kiro (AWS Builder ID OIDC) account farming pipeline → 9Router gateway integration

Resources

Stars

3 stars

Watchers

0 watching

Forks

Repository files navigation

⚡ Kiro Generator

Automated Kiro (AWS Builder ID OIDC) account provisioning pipeline → 9Router LLM gateway integration

Python License: MIT PRs Welcome GitHub

End-to-end, browser-automated registration of AWS Builder ID accounts with automatic integration into the 9Router LLM gateway. Fully scripted: temp inbox → OIDC device flow → camofox browser signup → token persistence → gateway insertion.


Table of Contents


Overview

Kiro Generator automates the complete lifecycle of AWS Builder ID accounts used to access AI coding services (CodeWhisperer / Kiro). From a single CLI invocation it:

  1. Creates a disposable inbox through Cloudflare-hosted temp-mail domains.
  2. Registers an OAuth 2.0 client against the AWS OIDC identity provider.
  3. Drives a camofox browser session (anti-bot-detection Chromium) through the device-authorization consent flow — email, name, OTP, password, allow.
  4. Persists the resulting accessToken / refreshToken pair to local account state.
  5. Inserts a fully-populated provider connection into 9Router's SQLite database so the account's models appear in the gateway's /v1/models catalog.

It also ships a model probing helper (test_models.py) for smoke-testing any candidate model through the OpenAI-compatible gateway endpoint.

Current status (August 2026): Kiro models (kr/*) appear in the 9Router catalog but cannot be used for chat completions — free AWS Builder ID accounts do not carry a profileArn, so CodeWhisperer requests fail with 400 profileArn is required. This repository remains a complete, working reference implementation of the AWS Builder ID OIDC + 9Router provider integration flow, and the scripts are provider-agnostic enough to be adapted once a qualifying account type is available.


Features

Feature Description
🧬 Full browser registration Headless camofox session drives the entire AWS consent flow — no manual steps
📧 Disposable inbox Random temp-mail addresses from 4 Cloudflare domains via cloudmail_client
🔑 AWS OIDC token lifecycle Device-code flow, token polling with retry, and refresh-token rotation
🔌 9Router integration Complete providerConnections row (authMethod, clientId, clientSecret, region, tokenEndpoint, scope)
💾 Persistent state Per-account JSON under accounts/kiro/, batch resume supported
🧪 Model probing test_models.py batch-smoke-tests any gateway model with tiny max_tokens
🔁 Refresh testing --refresh-test validates token rotation for an existing account
✅ Connection verification --verify checks a provider connection ID end-to-end

Why This Exists

Farming services such as 9Router aggregate free LLM provider accounts (FreeBuff, Blackbox, Kiro, QwenCloud…) behind an OpenAI-compatible API. The value is supplier diversity: when one provider rate-limits or dies, others keep the gateway healthy.

The blocker is registration friction — AWS Builder ID requires a real browser session, device-code consent, and OTP verification. This pipeline removes that friction:

  • No manual browser work: camofox does anti-bot-detection navigation so signups are not throttled by Cloudflare-style defenses.
  • No manual token handling: device-code → polling → refresh-rotation is fully scripted.
  • No manual SQL: provider rows are inserted with the exact providerSpecificData shape 9Router expects.

Architecture

┌─────────────┐    ┌───────────────────────┐    ┌─────────────────────────┐
│   camofox   │    │   kiro_generator.py   │    │   cloudmail_client.py  │
│  (browser)  │◄──►│  (orchestrator)       │◄──►│  (temp-mail API)       │
│ :9377       │    │  ─ OIDC device flow   │    │  4 CF domains          │
└─────────────┘    │  ─ AWS token polling  │    └─────────────────────────┘
                   │  ─ state persistence  │
                   └──────────┬────────────┘
                              │ providerConnections INSERT
                              ▼
                   ┌───────────────────────┐
                   │   9Router (SQLite)    │
                   │  :20128 /v1/models    │
                   └───────────────────────┘

Data flow, step by step:

  1. gen_password() / extract_email_from_jwt() prepare credentials for the signup.
  2. register_client() → POST to AWS OIDC client-registration endpoint → client_id + client_secret.
  3. device_authorization() → urn:ietf:params:oauth:grant-type:device_code grant → user code.
  4. camofox_open() / camofox_type() / camofox_click() drive the consent UI.
  5. poll_token() polls the token endpoint until the user approves (interval backoff, max_attempts cap).
  6. insert_9router_connection() writes the provider row with providerSpecificData.
  7. verify_connection() confirms the row is live in the gateway.

Requirements

Dependency Version / Endpoint Purpose
Python 3.10+ Runtime
camofox-browser localhost:9377 Anti-bot-detection Chromium automation
9Router localhost:20128 LLM gateway (OpenAI-compatible)
cloudmail_client.py on PYTHONPATH Cloudflare temp-mail API client

Both camofox and 9Router are assumed to be already running on their default ports. The generator talks to them over HTTP only.


Installation

# 1. Clone
git clone https://github.com/apissaj/kiro-generator.git
cd kiro-generator

# 2. (Optional) isolated venv
python -m venv .venv
source .venv/bin/activate   # Windows: .venv\Scripts\activate

# 3. Point PYTHONPATH at the temp-mail client
export PYTHONPATH=/path/to/cloudmail:$PYTHONPATH   # Windows: set PYTHONPATH=C:\path\to\cloudmail

# 4. Verify both services respond
curl -s http://localhost:9377/healthz    # camofox
curl -s http://localhost:20128/v1/models # 9Router (needs API key)

No third-party Python packages are required — the pipeline uses only the standard library (urllib, sqlite3, json, uuid, base64, …). The auxiliary registration scripts (kiro-custom-register.py, pipeline-kiro-full.py) use playwright + playwright-stealth instead of camofox; install those only if you use them:

pip install playwright playwright-stealth

Usage

# Create 1 account (default)
python kiro_generator.py

# Create 5 accounts in a batch
python kiro_generator.py --batch 5

# Resume from the last persisted state
python kiro_generator.py --resume

# Verify a provider connection by ID
python kiro_generator.py --verify <connection_id>

# Test refresh-token rotation for an existing account (by email)
python kiro_generator.py --refresh-test someone@gmail.com

# Smoke-test models through the 9Router gateway
python test_models.py GM/gemini-3.6-flash ML/deepseek-v4-flash

CLI Reference

kiro_generator.py

Flag Type Default Description
--batch N int 1 Number of accounts to provision in this run
--resume flag off Continue from the last persisted batch state
--verify ID str — Verify a 9Router provider connection ID
--refresh-test EMAIL str — Test OIDC refresh rotation for an existing account

test_models.py

Argument Description
model... (1+) Model IDs to probe (e.g. GM/gemini-3.6-flash)

Uses the first active API key in the 9Router database (%APPDATA%/9router/db/data.sqlite), sends a minimal chat completion (max_tokens=15, stream=false) and prints status, latency, error, and a content snippet per model. Zero-cost by design.


How It Works

Phase 1 — Discovery

Creates a fresh inbox through cloudmail_client.make_inbox() from one of the 4 active Cloudflare domains; generates a strong random password via gen_password().

Phase 2 — OIDC client registration

Registers a confidential client against the AWS codebuild SSO endpoint. The returned client_id / client_secret are stored per-account for token refresh.

Phase 3 — Device authorization

Starts the OAuth device flow (urn:ietf:params:oauth:grant-type:device_code). A short user code + verification URI are returned; the code is handed to the browser session.

Phase 4 — Browser consent (camofox)

Opens the verification URI in a camofox tab, then walks the form with snapshot-ref based typing/clicking: email → display name → OTP (delivered to the temp inbox) → password → confirm → Allow. The find_ref() helper locates form fields from the accessibility snapshot, so selectors never break on minor DOM changes.

Phase 5 — Token polling & persistence

Polls the token endpoint every interval seconds (max max_attempts). On success, saves the account record (email, clientId, clientSecret, accessToken, refreshToken, expiresIn) to accounts/kiro/<email>.json.

Phase 6 — 9Router insertion

Writes a providerConnections row with full providerSpecificData so the gateway can refresh tokens itself and expose the account's models under /v1/models.


9Router Integration

Each new account is inserted with a complete providerSpecificData payload:

{
  "authMethod": "external_idp",
  "region": "us-east-1",
  "clientId": "<client_id>",
  "clientSecret": "<client_secret>",
  "tokenEndpoint": "https://default.region-1.sso.awscodebuild.amazonaws.com/token",
  "scope": "codewhisperer:completions"
}

After insertion, models appear in the gateway:

curl -s http://localhost:20128/v1/models | jq '.data[].id' | grep '^"kr/'
kr/claude-opus-5          kr/claude-sonnet-4.5      kr/claude-haiku-4.5
kr/deepseek-3.2           kr/qwen3-coder-next       kr/glm-5
kr/MiniMax-M2.5           kr/gpt-5.6-sol            kr/gpt-5.6-terra
kr/gpt-5.6-luna           + thinking/agentic variants  (44 total)

⚠️ Known limitation: chat calls against these models currently fail with 400 {"message":"profileArn is required for this request."} because free AWS Builder ID accounts do not expose a profileArn (confirmed via ListAvailableProfiles → 403 and Kiro-Go's own isBuilderIDProfileUnsupportedError guard). The pipeline still provisions accounts correctly and remains the canonical reference for Builder ID OIDC + 9Router provider insertion.


Project Structure

kiro-generator/
├── kiro_generator.py          # Main pipeline: register → token → 9Router insert
├── kiro-custom-register.py    # Standalone Playwright-stealth registration (no camofox)
├── pipeline-kiro-full.py      # Register + auto-upgrade loop variant
├── test_models.py             # Gateway model smoke-test helper
├── test_kiro_eventstream.py   # AWS EventStream encoder debug tool (Kiro runtime)
├── accounts/kiro/             # Per-account state (git-ignored, contains tokens)
├── .gitignore                 # Anti-secret ignore rules (+ .example exceptions)
├── LICENSE                    # MIT
└── README.md                  # This document

Troubleshooting

Symptom Likely cause Fix
400 REQUEST_BODY_INVALID on eventstream test Wrong protocol/content-type for Kiro runtime Use JSON body for OAuth; see test_kiro_eventstream.py
profileArn is required for this request. Free AWS Builder ID account has no profileArn Not fixable per-account; provision accounts with qualifying AWS identity
Connection refused: :9377 camofox not running Start camofox server first
Connection refused: :20128 9Router not running Start 9Router gateway first
ModuleNotFoundError: cloudmail_client PYTHONPATH not set export PYTHONPATH=/path/to/cloudmail
Account exists but model 404 in gateway Stale DB row Re-run with --refresh-test to rotate tokens, then --verify

Security

  • Never commit account state. accounts/, token_test.json, device_auth_state.json, kiro_state.json are all git-ignored. The .gitignore keeps .example templates tracked while ignoring the real ones.
  • Tokens are treated as credentials. accessToken and refreshToken give API access — rotate immediately if ever exposed.
  • Scope of automation. This tool provisions accounts for your own use. Respect each service's Terms of Service and rate limits; do not resell or abuse.
  • Local-only by default. The pipeline talks only to localhost services; no telemetry, no callbacks, no external logs.

Roadmap

  • Support profileArn-capable account provisioning (AWS IAM Identity Center / org accounts)
  • Automatic fallback: when runtime.kiro.dev accepts eventstream chat, add a native Kiro runtime client
  • Multi-provider dry-run mode (--dry-run shows planned insert without touching DB)
  • Docker-compose for camofox + 9Router + generator
  • GitHub Actions smoke test that runs test_models.py against a mock gateway

Contributing

Contributions are welcome. Please:

  1. Fork the repository and open a PR against main.
  2. Keep the core pipeline standard-library only (urllib, sqlite3, json).
  3. Never commit or paste real tokens/credentials in issues, PRs, or code.
  4. Conventional commit messages (feat:, fix:, docs:, refactor:).
  5. If you add a browser-automation path, prefer camofox over raw Playwright.

Disclaimer

This project is provided as-is for educational and personal-automation purposes. The maintainers are not responsible for account bans, ToS violations, or any misuse. Check the terms of every service you automate, and stop if a service asks you to stop.


License

MIT © 2026 Hafizh Muzani

About

Automated Kiro (AWS Builder ID OIDC) account farming pipeline → 9Router gateway integration

Resources

Stars

3 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages