#!/usr/bin/env python3 """Delete and recreate NewAPI channels with correct type and base_url. Usage: python recreate_channels.py # type 1 (OpenAI), base URLs without /chat/completions python recreate_channels.py --custom # type 8 (Custom), base URLs with /chat/completions """ import argparse from newapi_client import ( add_channel, delete_channel, get_channel, list_channels, test_channel, TYPE_OPENAI, TYPE_CUSTOM, ) from channels_config import ( build_zhipuai, build_volcano_ark, build_minimax, ) def main(): parser = argparse.ArgumentParser(description="Recreate NewAPI channels") parser.add_argument("--custom", action="store_true", help="Use type 8 (Custom) with full endpoint URLs") args = parser.parse_args() channel_type = TYPE_CUSTOM if args.custom else TYPE_OPENAI full_url = args.custom type_label = "type 8 (Custom)" if args.custom else "type 1 (OpenAI)" # ─── Delete failing channels ───────────────────────────────── print("=== Deleting failing channels ===") for cid in [6, 7, 8, 9, 10, 12]: success, msg = delete_channel(cid) print(f" Delete ID={cid:2d} {'✅' if success else '❌'} {msg}") # ─── Recreate ──────────────────────────────────────────────── print(f"\n=== Recreating channels with {type_label} ===\n") # 1. ZhipuAI print("--- ZhipuAI ---") ch, n_keys = build_zhipuai(channel_type=channel_type, full_url=full_url) success, msg = add_channel(ch, mode="multi_to_single") print(f" ZhipuAI-Pool ({n_keys} keys) {'✅' if success else '❌'} {msg}") # 2. VolcanoArk print("\n--- VolcanoArk ---") for ch in build_volcano_ark(channel_type=channel_type, full_url=full_url): success, msg = add_channel(ch) print(f" {ch['name']} {'✅' if success else '❌'} {msg}") # 3. MiniMax print("\n--- MiniMax ---") ch = build_minimax(channel_type=channel_type, full_url=full_url) success, msg = add_channel(ch) print(f" MiniMax {'✅' if success else '❌'} {msg}") # ─── Verify base_url was set correctly ─────────────────────── print("\n=== Verifying base_urls ===") for ch in list_channels(): if ch["id"] >= 6: print(f" ID={ch['id']:2d} type={ch['type']:2d} name={ch['name']:30s} " f"base_url={ch['base_url']}") # ─── Test all new channels ─────────────────────────────────── print("\n=== Testing channels ===") new_ids = [ch["id"] for ch in list_channels() if ch["id"] >= 6] for cid in new_ids: ch = get_channel(cid) name = ch["name"] first_model = ch["models"].split(",")[0] print(f" ID={cid:2d} {name:30s} (model: {first_model})...", end=" ", flush=True) success, msg, _ = test_channel(cid) print(f"{'✅' if success else '❌'} {msg[:80]}") if __name__ == "__main__": main()