Skip to content

feat(examples): add Dedalus Labs and Cloudflare AI Gateway examples#508

Merged
richardsolomou merged 4 commits intomainfrom
feat/example-ai-dedalus
Apr 16, 2026
Merged

feat(examples): add Dedalus Labs and Cloudflare AI Gateway examples#508
richardsolomou merged 4 commits intomainfrom
feat/example-ai-dedalus

Conversation

@richardsolomou
Copy link
Copy Markdown
Member

@richardsolomou richardsolomou commented Apr 15, 2026

Problem

We don't have runnable examples for tracking Dedalus Labs or Cloudflare AI Gateway traffic in PostHog. Both expose OpenAI-compatible endpoints, so they slot into the existing OpenTelemetry auto-instrumentation pattern we already use for OpenRouter.

Changes

Two new examples under examples/:

  • example-ai-dedalus — OpenAI SDK pointed at https://api.dedaluslabs.ai/v1, DEDALUS_API_KEY, models as provider/model-id (e.g. openai/gpt-5-mini).
  • example-ai-cloudflare-ai-gateway — OpenAI SDK pointed at the compat endpoint (https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/compat), upstream provider API key with cf-aig-authorization header for gateway auth, provider/model-id format.

Both follow the same structure as the existing OTel examples (chat.py, pyproject.toml, README.md, uv.toml, uv.lock, .env.example) and stream spans through PostHogSpanProcessor via OpenAIInstrumentor.

Stacked on #482.

How did you test this code?

Ran the Node.js Cloudflare AI Gateway example end-to-end against a real PostHog project and confirmed $ai_generation events land. The Python example follows the same pattern. To verify:

cd examples/example-ai-dedalus
cp .env.example .env  # fill in keys
uv sync && source .env && uv run python chat.py

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Apr 15, 2026

Prompt To Fix All With AI
This is a comment left during a code review.
Path: examples/example-ai-dedalus/chat.py
Line: 36

Comment:
**Likely copy-paste model name from Cloudflare example**

Dedalus Labs is a direct OpenAI-compatible gateway, so the `openai/` provider prefix in `"openai/gpt-5-mini"` is almost certainly a copy-paste from the Cloudflare `compat` endpoint (which _requires_ a provider prefix to route across multiple providers). All other OpenAI-compatible gateway examples in this repo (Helicone, Vercel) use bare model names like `"gpt-5-mini"`. Unless Dedalus Labs explicitly requires this prefix, this should match the standard pattern.

```suggestion
    model="gpt-5-mini",
```

How can I resolve this? If you propose a fix, please make it concise.

---

This is a comment left during a code review.
Path: examples/example-ai-cloudflare-ai-gateway/README.md
Line: 14

Comment:
**`POSTHOG_API_KEY` missing from required-vars list**

The code uses `os.environ["POSTHOG_API_KEY"]` (hard key lookup, not `get`), so it will raise a `KeyError` if unset. The README currently lists only the Cloudflare-specific keys as required, leaving users to discover the missing PostHog key at runtime.

```suggestion
`POSTHOG_API_KEY`, `CLOUDFLARE_ACCOUNT_ID`, `CLOUDFLARE_GATEWAY_ID`, and `OPENAI_API_KEY` are required.
```

How can I resolve this? If you propose a fix, please make it concise.

Reviews (1): Last reviewed commit: "feat(examples): add Dedalus Labs and Clo..." | Re-trigger Greptile

Comment thread examples/example-ai-dedalus/chat.py
Comment thread examples/example-ai-cloudflare-ai-gateway/README.md Outdated
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 15, 2026

posthog-python Compliance Report

Date: 2026-04-16 10:35:35 UTC
Duration: 160003ms

⚠️ Some Tests Failed

29/30 tests passed, 1 failed


Capture Tests

29/29 tests passed

View Details
Test Status Duration
Format Validation.Event Has Required Fields 517ms
Format Validation.Event Has Uuid 1507ms
Format Validation.Event Has Lib Properties 1507ms
Format Validation.Distinct Id Is String 1507ms
Format Validation.Token Is Present 1507ms
Format Validation.Custom Properties Preserved 1507ms
Format Validation.Event Has Timestamp 1507ms
Retry Behavior.Retries On 503 9519ms
Retry Behavior.Does Not Retry On 400 3506ms
Retry Behavior.Does Not Retry On 401 3508ms
Retry Behavior.Respects Retry After Header 9510ms
Retry Behavior.Implements Backoff 23531ms
Retry Behavior.Retries On 500 7508ms
Retry Behavior.Retries On 502 7511ms
Retry Behavior.Retries On 504 7513ms
Retry Behavior.Max Retries Respected 23524ms
Deduplication.Generates Unique Uuids 1502ms
Deduplication.Preserves Uuid On Retry 7510ms
Deduplication.Preserves Uuid And Timestamp On Retry 14524ms
Deduplication.Preserves Uuid And Timestamp On Batch Retry 7509ms
Deduplication.No Duplicate Events In Batch 1503ms
Deduplication.Different Events Have Different Uuids 1508ms
Compression.Sends Gzip When Enabled 1507ms
Batch Format.Uses Proper Batch Structure 1507ms
Batch Format.Flush With No Events Sends Nothing 1005ms
Batch Format.Multiple Events Batched Together 1505ms
Error Handling.Does Not Retry On 403 3507ms
Error Handling.Does Not Retry On 413 3509ms
Error Handling.Retries On 408 7510ms

Feature_Flags Tests

⚠️ 0/1 tests passed, 1 failed

View Details
Test Status Duration
Request Payload.Request With Person Properties Device Id 505ms

Failures

request_payload.request_with_person_properties_device_id

404, message='NOT FOUND', url='http://sdk-adapter:8080/get_feature_flag'

Copy link
Copy Markdown
Member Author

richardsolomou commented Apr 15, 2026

@richardsolomou richardsolomou changed the base branch from feat/otel-examples to graphite-base/508 April 15, 2026 12:00
@richardsolomou richardsolomou requested a review from a team as a code owner April 15, 2026 12:02
@richardsolomou richardsolomou force-pushed the feat/example-ai-dedalus branch from d894c81 to 3da5dfa Compare April 15, 2026 12:02
@graphite-app graphite-app bot changed the base branch from graphite-base/508 to master April 15, 2026 12:03
@richardsolomou richardsolomou force-pushed the feat/example-ai-dedalus branch from 3da5dfa to f65a99c Compare April 15, 2026 12:03
Base automatically changed from master to main April 16, 2026 08:09
…way auth

The gateway requires the upstream provider key as the main API key and
the CF AI Gateway token via the cf-aig-authorization header.
@richardsolomou richardsolomou force-pushed the feat/example-ai-dedalus branch from 5da0473 to b54d0fc Compare April 16, 2026 10:30
@socket-security
Copy link
Copy Markdown

socket-security bot commented Apr 16, 2026

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Addedposthog@​7.11.199100100100100

View full report

@richardsolomou richardsolomou merged commit a221153 into main Apr 16, 2026
27 checks passed
@richardsolomou richardsolomou deleted the feat/example-ai-dedalus branch April 16, 2026 10:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants