Skip to content

Commit e1995df

Browse files
committed
Token counting proxy
1 parent 23c9d1e commit e1995df

File tree

16 files changed

+896
-35
lines changed

16 files changed

+896
-35
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# Binaries
22
bin/
33
dist/
4+
catty-api
5+
catty-proxy
6+
catty-exec-runtime
47
*.exe
58
*.dll
69
*.so

AGENTS.md

Lines changed: 243 additions & 21 deletions
Large diffs are not rendered by default.

Dockerfile.api

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM golang:1.25-bookworm AS builder
1+
FROM golang:1.25-alpine AS builder
22

33
WORKDIR /app
44

@@ -12,12 +12,10 @@ COPY . .
1212
# Build
1313
RUN CGO_ENABLED=0 go build -ldflags="-s -w" -o /catty-api ./cmd/catty-api
1414

15-
# Runtime image - minimal for API server
16-
FROM debian:bookworm-slim
15+
# Runtime image - minimal Alpine for API server
16+
FROM alpine:3.21
1717

18-
RUN apt-get update && apt-get install -y --no-install-recommends \
19-
ca-certificates \
20-
&& rm -rf /var/lib/apt/lists/*
18+
RUN apk add --no-cache ca-certificates
2119

2220
COPY --from=builder /catty-api /usr/local/bin/
2321

File renamed without changes.

Dockerfile.proxy

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
FROM golang:1.25-alpine AS builder
2+
3+
WORKDIR /app
4+
5+
# Copy go mod files
6+
COPY go.mod go.sum* ./
7+
RUN go mod download
8+
9+
# Copy source
10+
COPY . .
11+
12+
# Build
13+
RUN CGO_ENABLED=0 go build -ldflags="-s -w" -o /catty-proxy ./cmd/catty-proxy
14+
15+
# Runtime image - minimal Alpine for proxy server
16+
FROM alpine:3.21
17+
18+
RUN apk add --no-cache ca-certificates
19+
20+
COPY --from=builder /catty-proxy /usr/local/bin/
21+
22+
EXPOSE 8080
23+
24+
CMD ["catty-proxy"]

Makefile

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
.PHONY: build build-cli build-api release clean
1+
.PHONY: build build-cli build-api build-proxy release clean
22

33
VERSION ?= 0.1.0
44
LDFLAGS := -ldflags="-s -w -X main.Version=$(VERSION)"
55

66
# Build all binaries
7-
build: build-cli build-api
7+
build: build-cli build-api build-proxy
88

99
# Build CLI for current platform
1010
build-cli:
@@ -14,6 +14,10 @@ build-cli:
1414
build-api:
1515
go build $(LDFLAGS) -o bin/catty-api ./cmd/catty-api
1616

17+
# Build proxy for current platform
18+
build-proxy:
19+
go build $(LDFLAGS) -o bin/catty-proxy ./cmd/catty-proxy
20+
1721
# Build CLI for all platforms (for releases)
1822
release:
1923
@mkdir -p dist
@@ -25,9 +29,13 @@ release:
2529
deploy-api:
2630
fly deploy -c fly.api.toml
2731

32+
# Deploy proxy to Fly
33+
deploy-proxy:
34+
fly deploy -c fly.proxy.toml
35+
2836
# Deploy executor to Fly
2937
deploy-exec:
30-
fly deploy
38+
fly deploy -c fly.exec.toml
3139

3240
# Clean build artifacts
3341
clean:

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,12 @@ Maximum upload size: 100MB
7878

7979
- ~~**Custom domain** - Move away from *.fly.dev URLs~~
8080
- ~~**Persistent storage** - PostgreSQL for sessions and users~~
81+
- ~~**Usage metering** - Token counting via proxy~~
8182
- **Session reconnect** - Reconnect to existing sessions via `catty connect <label>` (WIP - DB done, reconnect buggy)
8283
- **Progress indicators** - Progress bars for uploads and other long operations
8384
- **Workspace sync-back** - Stream file changes from remote session back to local
8485
- **Documentation site** - Comprehensive docs with Mintlify
85-
- **Usage metering & billing** - Track per-user token usage, free tier + subscription ($25/mo target)
86+
- **Stripe billing** - Connect usage tracking to payments, free tier + subscription ($25/mo target)
8687
- **Multi-key support** - Pool of API keys for handling load spikes
8788

8889
## Development

catty-api

5.5 MB
Binary file not shown.

cmd/catty-exec-runtime/main.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,18 @@ func main() {
2525
addr = ":8080"
2626
}
2727

28+
// Log key env vars for debugging (without exposing full values)
29+
if baseURL := os.Getenv("ANTHROPIC_BASE_URL"); baseURL != "" {
30+
slog.Info("anthropic config", "base_url", baseURL)
31+
}
32+
if apiKey := os.Getenv("ANTHROPIC_API_KEY"); apiKey != "" {
33+
preview := apiKey
34+
if len(apiKey) > 20 {
35+
preview = apiKey[:20] + "..."
36+
}
37+
slog.Info("anthropic config", "api_key_preview", preview, "api_key_length", len(apiKey))
38+
}
39+
2840
server := executor.NewServer()
2941

3042
httpServer := &http.Server{

fly.toml renamed to fly.exec.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ app = "catty-exec"
1212
primary_region = "iad"
1313

1414
[build]
15-
dockerfile = "Dockerfile"
15+
dockerfile = "Dockerfile.exec"
1616

1717
[http_service]
1818
internal_port = 8080

0 commit comments

Comments
 (0)