Skip to content

nopperabbo/codebuddy2api

Repository files navigation

CodeBuddy2API + Kiro Gateway

OpenAI-compatible proxy for CodeBuddy and Kiro (Amazon Q Developer) β€” access Claude Opus 4.7, Sonnet 4.5, GLM-5, Qwen3, and more via a single local API.


✨ Features

  • πŸ”‘ Kiro Gateway β€” Use ksk_ API keys from Kiro IDE to access Claude models via AWS
  • πŸ€– 10+ AI Models β€” Claude Opus 4.7, Opus 4.5, Sonnet 4.5, Haiku 4.5, GLM-5, Qwen3, Minimax, and more
  • πŸ”„ Key Rotation β€” Automatic round-robin across multiple API keys
  • πŸ“‘ OpenAI-Compatible β€” Works with OpenCode, Cursor, Continue, and any OpenAI-compatible client
  • 🌊 Streaming Support β€” Real-time SSE streaming responses
  • πŸ›‘οΈ Error Recovery β€” Auto-retry with key rotation on 403/429 errors

πŸ“‹ Prerequisites

  • Python 3.10+
  • Kiro IDE account (free) β€” to get your ksk_ API key
  • Git

πŸš€ Quick Start

1. Clone the Repository

git clone https://github.com/nopperabbo/codebuddy2api.git
cd codebuddy2api

2. Set Up Virtual Environment

python3 -m venv venv
source venv/bin/activate  # macOS/Linux
# or: venv\Scripts\activate  # Windows

3. Install Dependencies

pip install -r requirements.txt

4. Configure Environment

cp .env.example .env

Edit .env and set your password:

CODEBUDDY_PASSWORD=your_secret_password_here

5. Add Your Kiro API Key(s)

Create kiro_keys.json in the project root:

[
  {"api_key": "ksk_YOUR_FIRST_KEY_HERE"},
  {"api_key": "ksk_YOUR_SECOND_KEY_HERE"}
]

πŸ’‘ How to get your ksk_ key: Open Kiro IDE, sign in, then find your API key in Settings β†’ API Keys. It starts with ksk_.

6. Start the Server

bash start.sh

The server will start on http://localhost:8003.


🎯 Available Models (Kiro Gateway)

Model ID Description Status
claude-opus-4.7 Claude Opus 4.7 β€” Latest & most capable βœ…
claude-opus-4.5 Claude Opus 4.5 βœ…
claude-sonnet-4.5 Claude Sonnet 4.5 βœ…
claude-haiku-4.5 Claude Haiku 4.5 β€” Fast & light βœ…
claude-sonnet-4 Claude Sonnet 4 βœ…
glm-5 GLM-5 (via Kiro) βœ…
qwen3-coder-next Qwen3 Coder Next (via Kiro) βœ…
minimax-m2.5 Minimax M2.5 (via Kiro) βœ…
minimax-m2.1 Minimax M2.1 (via Kiro) βœ…
auto Let Kiro pick the best model βœ…

πŸ”— API Endpoints

Kiro Gateway

Method Endpoint Description
GET /kiro/v1/models List available Kiro models
POST /kiro/v1/chat/completions Chat completions (OpenAI-compatible)
GET /kiro/v1/keys List configured API keys (masked)
POST /kiro/v1/keys Add a new API key

CodeBuddy (Original)

Method Endpoint Description
GET /codebuddy/v1/models List CodeBuddy models
POST /codebuddy/v1/chat/completions Chat completions
GET /codebuddy/v1/credentials List credentials

πŸ§ͺ Quick Test

Test with curl

# List models
curl -s -H "Authorization: Bearer YOUR_PASSWORD" \
  http://localhost:8003/kiro/v1/models | python3 -m json.tool

# Chat with Opus 4.7
curl -s -X POST http://localhost:8003/kiro/v1/chat/completions \
  -H "Authorization: Bearer YOUR_PASSWORD" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "claude-opus-4.7",
    "messages": [{"role": "user", "content": "Hello!"}],
    "stream": false
  }'

# Streaming
curl -N -X POST http://localhost:8003/kiro/v1/chat/completions \
  -H "Authorization: Bearer YOUR_PASSWORD" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "claude-opus-4.7",
    "messages": [{"role": "user", "content": "Write a haiku about coding"}],
    "stream": true
  }'

πŸ› οΈ Integration with OpenCode

Add this to your ~/.config/opencode/opencode.json under the "provider" section:

"kiro": {
  "models": {
    "claude-opus-4.7": {
      "limit": { "context": 200000, "output": 64000 },
      "name": "Claude Opus 4.7 (Kiro/AWS)",
      "modalities": {
        "input": ["text", "image", "pdf"],
        "output": ["text"]
      },
      "variants": {
        "low": { "thinkingConfig": { "thinkingBudget": 16384 } },
        "medium": { "thinkingConfig": { "thinkingBudget": 32768 } },
        "high": { "thinkingConfig": { "thinkingBudget": 65536 } },
        "max": { "thinkingConfig": { "thinkingBudget": 128000 } }
      }
    },
    "claude-opus-4.5": {
      "limit": { "context": 200000, "output": 64000 },
      "name": "Claude Opus 4.5 (Kiro/AWS)",
      "modalities": {
        "input": ["text", "image", "pdf"],
        "output": ["text"]
      },
      "variants": {
        "low": { "thinkingConfig": { "thinkingBudget": 16384 } },
        "medium": { "thinkingConfig": { "thinkingBudget": 32768 } },
        "high": { "thinkingConfig": { "thinkingBudget": 65536 } },
        "max": { "thinkingConfig": { "thinkingBudget": 128000 } }
      }
    },
    "claude-sonnet-4": {
      "limit": { "context": 200000, "output": 64000 },
      "name": "Claude Sonnet 4 (Kiro/AWS)",
      "modalities": {
        "input": ["text", "image", "pdf"],
        "output": ["text"]
      },
      "variants": {
        "low": { "thinkingConfig": { "thinkingBudget": 8192 } },
        "medium": { "thinkingConfig": { "thinkingBudget": 16384 } },
        "high": { "thinkingConfig": { "thinkingBudget": 24576 } },
        "max": { "thinkingConfig": { "thinkingBudget": 32768 } }
      }
    },
    "auto": {
      "limit": { "context": 200000, "output": 64000 },
      "name": "Auto (Kiro/AWS Best Pick)",
      "modalities": {
        "input": ["text", "image", "pdf"],
        "output": ["text"]
      },
      "variants": {
        "low": { "thinkingConfig": { "thinkingBudget": 8192 } },
        "medium": { "thinkingConfig": { "thinkingBudget": 16384 } },
        "high": { "thinkingConfig": { "thinkingBudget": 24576 } },
        "max": { "thinkingConfig": { "thinkingBudget": 32768 } }
      }
    }
  },
  "name": "Kiro (Amazon Q)",
  "npm": "@ai-sdk/openai-compatible",
  "options": {
    "apiKey": "YOUR_PASSWORD",
    "baseURL": "http://127.0.0.1:8003/kiro/v1"
  }
}

Then select kiro/claude-opus-4.7 as your model in OpenCode.


πŸ”§ Integration with Cursor / Continue / Other Tools

Use these settings in any OpenAI-compatible client:

Setting Value
Base URL http://localhost:8003/kiro/v1
API Key Your CODEBUDDY_PASSWORD from .env
Model claude-opus-4.7 (or any from the list above)

πŸ“ Project Structure

codebuddy2api/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ __init__.py
β”‚   β”œβ”€β”€ auth.py              # Authentication middleware
β”‚   β”œβ”€β”€ codebuddy_router.py  # CodeBuddy proxy router
β”‚   β”œβ”€β”€ kiro_api_client.py   # Kiro API client & model mapping
β”‚   β”œβ”€β”€ kiro_router.py       # Kiro gateway router
β”‚   └── ...
β”œβ”€β”€ kiro_keys.json           # Your ksk_ API keys (gitignored)
β”œβ”€β”€ .env                     # Environment config (gitignored)
β”œβ”€β”€ .env.example             # Example environment file
β”œβ”€β”€ requirements.txt         # Python dependencies
β”œβ”€β”€ start.sh                 # Startup script
└── web.py                   # Main application entry point

⚠️ Important Notes

  • Keep your ksk_ keys safe β€” they provide direct access to the Kiro API
  • kiro_keys.json is gitignored β€” your keys will never be accidentally committed
  • The server runs on port 8003 by default
  • All requests require the Authorization: Bearer YOUR_PASSWORD header
  • Multiple ksk_ keys are supported β€” the server rotates through them automatically

🀝 Credits


πŸ“„ License

MIT

About

Akses AI model premium (Claude, GPT-5, Gemini) gratis lewat CodeBuddy β€” OpenAI-compatible API server

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors