Phase 8 Production Hardening with complete governance infrastructure: - Vault integration with tiered policies (T0-T4) - DragonflyDB state management - SQLite audit ledger - Pipeline DSL and templates - Promotion/revocation engine - Checkpoint system for session persistence - Health manager and circuit breaker for fault tolerance - GitHub/Slack integrations - Architectural test pipeline with bug watcher, suggestion engine, council review - Multi-agent chaos testing framework Test Results: - Governance tests: 68/68 passing - E2E workflow: 16/16 passing - Phase 2 Vault: 14/14 passing - Integration tests: 27/27 passing Coverage: 57.6% average across 12 phases Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
58 lines
1.6 KiB
Python
58 lines
1.6 KiB
Python
#!/usr/bin/env python3
|
|
"""Test OpenRouter API with Python/uv"""
|
|
|
|
import json
|
|
import os
|
|
from openai import OpenAI
|
|
|
|
def get_api_key_from_vault():
|
|
"""Retrieve API key from Vault using curl"""
|
|
import subprocess
|
|
|
|
# Get root token
|
|
with open("/opt/vault/init-keys.json") as f:
|
|
token = json.load(f)["root_token"]
|
|
|
|
# Fetch from Vault API directly
|
|
result = subprocess.run([
|
|
"curl", "-sk",
|
|
"-H", f"X-Vault-Token: {token}",
|
|
"https://127.0.0.1:8200/v1/secret/data/api-keys/openrouter"
|
|
], capture_output=True, text=True)
|
|
|
|
data = json.loads(result.stdout)
|
|
return data["data"]["data"]["api_key"]
|
|
|
|
def main():
|
|
print("=== Python/uv OpenRouter Test ===\n")
|
|
|
|
# Get API key from Vault
|
|
print("Fetching API key from Vault...")
|
|
api_key = get_api_key_from_vault()
|
|
print(f"API key retrieved: {api_key[:20]}...\n")
|
|
|
|
# Initialize OpenAI client with OpenRouter
|
|
client = OpenAI(
|
|
base_url="https://openrouter.ai/api/v1",
|
|
api_key=api_key,
|
|
)
|
|
|
|
# Test request
|
|
print("Sending test request to OpenRouter...")
|
|
response = client.chat.completions.create(
|
|
model="anthropic/claude-3.5-haiku",
|
|
messages=[
|
|
{"role": "user", "content": "Say 'Hello from OpenRouter!' and nothing else."}
|
|
],
|
|
max_tokens=50
|
|
)
|
|
|
|
print(f"Model: {response.model}")
|
|
print(f"Response: {response.choices[0].message.content}")
|
|
print(f"Usage: {response.usage.prompt_tokens} prompt, {response.usage.completion_tokens} completion")
|
|
|
|
return response
|
|
|
|
if __name__ == "__main__":
|
|
main()
|