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 claude -p for auth, no env var requirement · majorcontext/keep@4196bb2

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
+51-81Lines changed: 51 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
# Runs the keep-llm-gateway in front of the Anthropic API and demonstrates
66
# policy enforcement: streaming, redaction, and audit logging.
77
#
8-
# Prerequisites:
9-
# - ANTHROPIC_API_KEY set in your environment
8+
# Auth is handled by `claude -p`, which picks up credentials from wherever
9+
# you have them configured (OAuth, API key, etc.).
1010
#
1111
# Usage:
1212
# ./examples/llm-gateway-demo/demo.sh
@@ -24,11 +24,6 @@ cleanup() {
2424
}
2525
trap cleanup EXIT
2626

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-
3227
echo "=== Keep LLM Gateway Demo ==="
3328
echo ""
3429

@@ -51,91 +46,72 @@ sleep 1
5146
echo " Gateway running (PID $GW_PID)"
5247
echo ""
5348

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")
49+
export ANTHROPIC_BASE_URL="http://localhost:${GW_PORT}"
5650

57-
# ── Test 1: Streaming request ─────────────────────────────────────
51+
# ── Test 1: Streaming request via claude -p ───────────────────────
5852
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
5953
echo "Test 1: Streaming request through the gateway"
6054
echo ""
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
55+
echo " \$ ANTHROPIC_BASE_URL=$ANTHROPIC_BASE_URL claude -p 'What is 2+2?'"
8256
echo ""
8357

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')
98-
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"
58+
if timeout 30 claude -p "What is 2+2? Answer in exactly one word, no punctuation." \
59+
--model claude-haiku-4-5-20251001 \
60+
--max-turns 1 2>&1; then
61+
echo ""
62+
echo " ✓ Streaming request succeeded"
10263
else
103-
echo " ✗ HTTP $HTTP_CODE — $BODY"
64+
EXIT_CODE=$?
65+
echo ""
66+
if [ "$EXIT_CODE" -eq 124 ]; then
67+
echo " ✗ Timed out after 30s"
68+
else
69+
echo " ✗ claude exited with code $EXIT_CODE"
70+
fi
10471
fi
10572
echo ""
10673

107-
# ── Test 3: Secret redaction ──────────────────────────────────────
74+
# ── Test 2: Secret redaction ──────────────────────────────────────
10875
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
109-
echo "Test 3: Secret redaction in tool results"
76+
echo "Test 2: Secret redaction in tool results"
11077
echo ""
11178
echo " Sending a tool_result containing an AWS key and password."
11279
echo " The gateway redacts secrets before forwarding to the model."
11380
echo ""
11481

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"
82+
if [ -n "${ANTHROPIC_API_KEY:-}" ]; then
83+
RESPONSE=$(curl -s -w "\n%{http_code}" \
84+
"$ANTHROPIC_BASE_URL/v1/messages" \
85+
-H "Content-Type: application/json" \
86+
-H "anthropic-version: 2023-06-01" \
87+
-H "x-api-key: $ANTHROPIC_API_KEY" \
88+
-d '{
89+
"model": "claude-haiku-4-5-20251001",
90+
"max_tokens": 100,
91+
"messages": [
92+
{"role": "user", "content": "Read the .env file"},
93+
{"role": "assistant", "content": [
94+
{"type": "tool_use", "id": "tool_1", "name": "bash", "input": {"command": "cat .env"}}
95+
]},
96+
{"role": "user", "content": [
97+
{"type": "tool_result", "tool_use_id": "tool_1", "content": "DB_HOST=localhost\nAWS_ACCESS_KEY_ID=AKIAIOSFODNN7EXAMPLE\npassword = hunter2\nAPP_NAME=myapp"}
98+
]}
99+
]
100+
}' 2>&1)
101+
102+
HTTP_CODE=$(echo "$RESPONSE" | tail -1)
103+
BODY=$(echo "$RESPONSE" | sed '$d')
104+
105+
if [ "$HTTP_CODE" = "200" ]; then
106+
echo " ✓ HTTP 200 — Model responded (secrets were redacted before reaching it)"
107+
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)")
108+
echo " Model said: $ANSWER"
109+
else
110+
echo " ✗ HTTP $HTTP_CODE — $BODY"
111+
fi
137112
else
138-
echo " ✗ HTTP $HTTP_CODE — $BODY"
113+
echo " ~ Skipped: ANTHROPIC_API_KEY not set (needed for curl-based redaction test)"
114+
echo " Redaction is verified by unit tests: make test-unit ARGS='-run TestProxy_RedactRequest'"
139115
fi
140116
echo ""
141117

@@ -169,9 +145,3 @@ fi
169145
echo ""
170146
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
171147
echo "Demo complete."
172-
echo ""
173-
echo "You can also point claude at the gateway:"
174-
echo " ANTHROPIC_BASE_URL=http://localhost:${GW_PORT} claude"
175-
echo ""
176-
echo "Response deny (blocking destructive commands) is covered by unit tests:"
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.