#!/usr/bin/env python3 """Add new usable API keys as channels to NewAPI — without modifying existing channels.""" from newapi_client import ( add_channel, list_channels, list_channel_names, test_channel, TYPE_OPENAI, TYPE_OLLAMA, ) from channels_config import build_stepfun, build_ollama_cloud, build_baidu_qianfan def main(): existing = list_channel_names() print(f"Existing channels: {sorted(existing)}\n") new_channels = [] # ─── 1. StepFun (阶跃星辰) — Anthropic-compatible ─────────────── if "StepFun" not in existing: new_channels.append(build_stepfun()) else: print("[SKIP] StepFun already exists") # ─── 2. Ollama Cloud ──────────────────────────────────────────── if "OllamaCloud" not in existing: new_channels.append(build_ollama_cloud()) else: print("[SKIP] OllamaCloud already exists") # ─── 3. Baidu Qianfan Coding Plan ─────────────────────────────── if "BaiduQianfan-Coding" not in existing: new_channels.append(build_baidu_qianfan()) else: print("[SKIP] BaiduQianfan-Coding already exists") # ─── Add all new channels ─────────────────────────────────────── for ch in new_channels: print(f"[ADD] {ch['name']} (type={ch['type']})...") success, msg = add_channel(ch) print(f" -> success={success} msg={msg}") # If Ollama type 37 failed, retry as OpenAI type 1 if not success and ch["type"] == TYPE_OLLAMA: print(f" -> Retrying {ch['name']} as OpenAI type (1)...") ch["type"] = TYPE_OPENAI success, msg = add_channel(ch) print(f" -> success={success} msg={msg}") # Test the channel if added successfully if success: for c in list_channels(): if c["name"] == ch["name"]: print(f" -> Testing channel ID={c['id']}...") t_success, t_msg, _ = test_channel(c["id"]) print(f" -> test: success={t_success} msg={t_msg[:100]}") break print() # ─── Final listing ────────────────────────────────────────────── print("=== All channels after update: ===\n") for ch in list_channels(): print(f" ID={ch['id']:3d} type={ch['type']:2d} status={ch['status']} " f"name={ch['name']:35s} models={str(ch.get('models', ''))[:80]}") if __name__ == "__main__": main()