GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(demo): use curl with ANTHROPIC_API_KEY instead of claude -p · majorcontext/keep@cf24125

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • examples/llm-gateway-demo
    • demo.sh
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎examples/llm-gateway-demo/demo.sh‎

Copy file name to clipboardExpand all lines: examples/llm-gateway-demo/demo.sh
+80-51Lines changed: 80 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,10 @@
33
# Keep LLM Gateway Demo
44
#
55
# Runs the keep-llm-gateway in front of the Anthropic API and demonstrates
6-
# policy enforcement. Uses `claude -p` for streaming and curl for structured
7-
# requests (redaction).
6+
# policy enforcement: streaming, redaction, and audit logging.
87
#
98
# Prerequisites:
10-
# - claude CLI installed with valid credentials
11-
# - ANTHROPIC_API_KEY set (for curl-based tests)
9+
# - ANTHROPIC_API_KEY set in your environment
1210
#
1311
# Usage:
1412
# ./examples/llm-gateway-demo/demo.sh
@@ -26,6 +24,11 @@ cleanup() {
2624
}
2725
trap cleanup EXIT
2826

27+
if [ -z "${ANTHROPIC_API_KEY:-}" ]; then
28+
echo "ANTHROPIC_API_KEY is not set. Export it and re-run."
29+
exit 1
30+
fi
31+
2932
echo "=== Keep LLM Gateway Demo ==="
3033
echo ""
3134

@@ -36,7 +39,6 @@ echo " done"
3639
echo ""
3740

3841
# ── Start gateway ─────────────────────────────────────────────────
39-
# Generate config from template, filling in runtime paths.
4042
sed \
4143
-e "s|RULES_DIR|$SCRIPT_DIR/rules|" \
4244
-e "s|LOG_OUTPUT|$DEMO_DIR/audit.jsonl|" \
@@ -49,67 +51,91 @@ sleep 1
4951
echo " Gateway running (PID $GW_PID)"
5052
echo ""
5153

52-
# ── Test 1: claude -p through gateway ─────────────────────────────
54+
GW_URL="http://localhost:${GW_PORT}/v1/messages"
55+
GW_HEADERS=(-H "Content-Type: application/json" -H "anthropic-version: 2023-06-01" -H "x-api-key: $ANTHROPIC_API_KEY")
56+
57+
# ── Test 1: Streaming request ─────────────────────────────────────
5358
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
54-
echo "Test 1: claude -p through the gateway (streaming)"
59+
echo "Test 1: Streaming request through the gateway"
5560
echo ""
56-
echo " ANTHROPIC_BASE_URL=http://localhost:${GW_PORT} claude -p 'What is 2+2?'"
61+
62+
RESPONSE=$(curl -s -w "\n%{http_code}" "$GW_URL" "${GW_HEADERS[@]}" \
63+
-d '{
64+
"model": "claude-haiku-4-5-20251001",
65+
"max_tokens": 30,
66+
"stream": true,
67+
"messages": [{"role": "user", "content": "What is 2+2? Answer in one word."}]
68+
}' 2>&1)
69+
70+
HTTP_CODE=$(echo "$RESPONSE" | tail -1)
71+
BODY=$(echo "$RESPONSE" | sed '$d')
72+
73+
if [ "$HTTP_CODE" = "200" ]; then
74+
EVENT_COUNT=$(echo "$BODY" | grep -c "^event:" || true)
75+
echo " ✓ HTTP 200 — Received $EVENT_COUNT SSE events (buffered, policy-evaluated, replayed)"
76+
else
77+
echo " ✗ HTTP $HTTP_CODE — $BODY"
78+
echo ""
79+
echo " Check that ANTHROPIC_API_KEY is valid."
80+
exit 1
81+
fi
5782
echo ""
5883

59-
CLAUDE_OUTPUT=$(ANTHROPIC_BASE_URL="http://localhost:${GW_PORT}" \
60-
claude -p "What is 2+2? Answer in exactly one word, no punctuation." \
61-
--model claude-haiku-4-5-20251001 \
62-
--max-turns 1 \
63-
2>&1) || true
84+
# ── Test 2: Non-streaming request ─────────────────────────────────
85+
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
86+
echo "Test 2: Non-streaming request through the gateway"
87+
echo ""
88+
89+
RESPONSE=$(curl -s -w "\n%{http_code}" "$GW_URL" "${GW_HEADERS[@]}" \
90+
-d '{
91+
"model": "claude-haiku-4-5-20251001",
92+
"max_tokens": 30,
93+
"messages": [{"role": "user", "content": "What is 2+2? Answer in one word."}]
94+
}' 2>&1)
95+
96+
HTTP_CODE=$(echo "$RESPONSE" | tail -1)
97+
BODY=$(echo "$RESPONSE" | sed '$d')
6498

65-
if [ -n "$CLAUDE_OUTPUT" ]; then
66-
echo " ✓ Claude response: $CLAUDE_OUTPUT"
99+
if [ "$HTTP_CODE" = "200" ]; then
100+
ANSWER=$(echo "$BODY" | python3 -c "import json,sys; r=json.load(sys.stdin); print(r['content'][0]['text'])" 2>/dev/null || echo "$BODY")
101+
echo " ✓ HTTP 200 — Model said: $ANSWER"
67102
else
68-
echo " ✗ claude -p produced no output"
69-
echo " Make sure claude is installed and has valid credentials."
103+
echo " ✗ HTTP $HTTP_CODE — $BODY"
70104
fi
71105
echo ""
72106

73-
# ── Test 2: Secret redaction ──────────────────────────────────────
107+
# ── Test 3: Secret redaction ──────────────────────────────────────
74108
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
75-
echo "Test 2: Secret redaction in tool results"
109+
echo "Test 3: Secret redaction in tool results"
76110
echo ""
77111
echo " Sending a tool_result containing an AWS key and password."
78112
echo " The gateway redacts secrets before forwarding to the model."
79113
echo ""
80114

81-
if [ -z "${ANTHROPIC_API_KEY:-}" ]; then
82-
echo " ~ Skipped: ANTHROPIC_API_KEY not set (needed for curl-based tests)"
115+
RESPONSE=$(curl -s -w "\n%{http_code}" "$GW_URL" "${GW_HEADERS[@]}" \
116+
-d '{
117+
"model": "claude-haiku-4-5-20251001",
118+
"max_tokens": 100,
119+
"messages": [
120+
{"role": "user", "content": "Read the .env file"},
121+
{"role": "assistant", "content": [
122+
{"type": "tool_use", "id": "tool_1", "name": "bash", "input": {"command": "cat .env"}}
123+
]},
124+
{"role": "user", "content": [
125+
{"type": "tool_result", "tool_use_id": "tool_1", "content": "DB_HOST=localhost\nAWS_ACCESS_KEY_ID=AKIAIOSFODNN7EXAMPLE\npassword = hunter2\nAPP_NAME=myapp"}
126+
]}
127+
]
128+
}' 2>&1)
129+
130+
HTTP_CODE=$(echo "$RESPONSE" | tail -1)
131+
BODY=$(echo "$RESPONSE" | sed '$d')
132+
133+
if [ "$HTTP_CODE" = "200" ]; then
134+
echo " ✓ HTTP 200 — Model responded (secrets were redacted before reaching it)"
135+
ANSWER=$(echo "$BODY" | python3 -c "import json,sys; r=json.load(sys.stdin); print(r['content'][0]['text'][:200])" 2>/dev/null || echo "(parse error)")
136+
echo " Model said: $ANSWER"
83137
else
84-
RESPONSE=$(curl -s -w "\n%{http_code}" \
85-
"http://localhost:${GW_PORT}/v1/messages" \
86-
-H "Content-Type: application/json" \
87-
-H "anthropic-version: 2023-06-01" \
88-
-H "x-api-key: $ANTHROPIC_API_KEY" \
89-
-d '{
90-
"model": "claude-haiku-4-5-20251001",
91-
"max_tokens": 100,
92-
"messages": [
93-
{"role": "user", "content": "Read the .env file"},
94-
{"role": "assistant", "content": [
95-
{"type": "tool_use", "id": "tool_1", "name": "bash", "input": {"command": "cat .env"}}
96-
]},
97-
{"role": "user", "content": [
98-
{"type": "tool_result", "tool_use_id": "tool_1", "content": "DB_HOST=localhost\nAWS_ACCESS_KEY_ID=AKIAIOSFODNN7EXAMPLE\npassword = hunter2\nAPP_NAME=myapp"}
99-
]}
100-
]
101-
}' 2>&1)
102-
103-
HTTP_CODE=$(echo "$RESPONSE" | tail -1)
104-
BODY=$(echo "$RESPONSE" | sed '$d')
105-
106-
if [ "$HTTP_CODE" = "200" ]; then
107-
echo " ✓ HTTP 200 — Model responded (secrets were redacted before reaching it)"
108-
ANSWER=$(echo "$BODY" | python3 -c "import json,sys; r=json.load(sys.stdin); print(r['content'][0]['text'][:200])" 2>/dev/null || echo "(parse error)")
109-
echo " Model said: $ANSWER"
110-
else
111-
echo " ✗ HTTP $HTTP_CODE — $BODY"
112-
fi
138+
echo " ✗ HTTP $HTTP_CODE — $BODY"
113139
fi
114140
echo ""
115141

@@ -144,5 +170,8 @@ echo ""
144170
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
145171
echo "Demo complete."
146172
echo ""
173+
echo "You can also point claude at the gateway:"
174+
echo " ANTHROPIC_BASE_URL=http://localhost:${GW_PORT} claude"
175+
echo ""
147176
echo "Response deny (blocking destructive commands) is covered by unit tests:"
148-
echo " make test-unit ARGS='-run TestProxy_StreamingDenyResponse ./internal/gateway'"
177+
echo " make test-unit ARGS='-run TestProxy_DenyResponse ./internal/gateway'"

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.