Title: Use Pydantic discriminator so we can easily parse webhooks · Issue #21 · VapiAI/server-sdk-python · GitHub
Open Graph Title: Use Pydantic discriminator so we can easily parse webhooks · Issue #21 · VapiAI/server-sdk-python
X Title: Use Pydantic discriminator so we can easily parse webhooks · Issue #21 · VapiAI/server-sdk-python
Description: Hi! We use the Vapi SDK for both the client but also for type checking in our webhooks we received. Currently, we have to do some reflection with Pydantic to more easily/programatically parse the events. However, Pydantic supports discri...
Open Graph Description: Hi! We use the Vapi SDK for both the client but also for type checking in our webhooks we received. Currently, we have to do some reflection with Pydantic to more easily/programatically parse the e...
X Description: Hi! We use the Vapi SDK for both the client but also for type checking in our webhooks we received. Currently, we have to do some reflection with Pydantic to more easily/programatically parse the e...
Opengraph URL: https://github.com/VapiAI/server-sdk-python/issues/21
X: @github
Domain: patch-diff.githubusercontent.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Use Pydantic discriminator so we can easily parse webhooks","articleBody":"Hi!\n\nWe use the Vapi SDK for both the client but also for type checking in our webhooks we received. Currently, we have to do some reflection with Pydantic to more easily/programatically parse the events.\n\nHowever, Pydantic supports discriminators https://docs.pydantic.dev/latest/concepts/fields/#discriminator where a field can determine the model type. It would be really nice to be able to do something like:\n\n```\n@router.post(\"/vapi/events\")\nasync def webhook_vapi_events(request: Request):\n # make sure the data coming in is from vapi\n if not authorize_vapi_webhook_request(request):\n logger.warning(\"Invalid secret supplied via webhook\")\n return JSONResponse(status_code=401, content={\"status\": \"error\", \"message\": \"Invalid secret\"})\n\n # continue processing\n json_data = await request.json()\n\n # parse our event\n event_type = VapiEvent.model_validate(json_data)\n\n # pydantic automatically maps/casts to the model\n # event_type: ServerMessageStatusUpdate in the case of `status-update`\n ...\n```\n\nCurrently, we have to have a mapping from `type` to each model like so:\n```\n message = json_data.get(\"message\")\n if not message:\n logger.warning(\"No message found in request\")\n return {\"status\": \"missing-message\"}\n\n raw_type = message.get(\"type\")\n if not raw_type:\n logger.warning(\"No message type found in request\")\n return {\"status\": \"missing-message-type\"}\n\n # we have to manually parse models\n event = mapping[raw_type]\n \n```\n\nWhere `mapping` is a generated via reflection from `ServerMessageStatusUpdate` etc based on the `type` field which used to be a default string but currently uses literals.\n\nAre there any future plans to support discriminators in the future to more easily parse these? I believe you use `fern` to generate your SDK and they do support this: https://buildwithfern.com/learn/api-definitions/ferndef/types#discriminated-unions\n","author":{"url":"https://github.com/emhagman","@type":"Person","name":"emhagman"},"datePublished":"2026-01-23T18:48:23.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/21/server-sdk-python/issues/21"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:9ae6c350-3ad1-aeda-9a08-2387906f6d06 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C280:3A3C79:1354E88:1BACDA1:697A3B0B |
| html-safe-nonce | d80a9fea76de2f19fb673ebeed08211a1f9f050cb5e5ac01608bedfd348b8e96 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDMjgwOjNBM0M3OToxMzU0RTg4OjFCQUNEQTE6Njk3QTNCMEIiLCJ2aXNpdG9yX2lkIjoiODM1OTI2MjA3NTA3ODk4MjQxMSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 0990770ef5f126af573813a2484e764373ac497f40bee793ab1932590a78f6ce |
| hovercard-subject-tag | issue:3848719586 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/VapiAI/server-sdk-python/21/issue_layout |
| twitter:image | https://opengraph.githubassets.com/e73147a7ee35c597ba47b32b5753ffe3ef3b7a291dde8fb98d40af7daba7aac7/VapiAI/server-sdk-python/issues/21 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/e73147a7ee35c597ba47b32b5753ffe3ef3b7a291dde8fb98d40af7daba7aac7/VapiAI/server-sdk-python/issues/21 |
| og:image:alt | Hi! We use the Vapi SDK for both the client but also for type checking in our webhooks we received. Currently, we have to do some reflection with Pydantic to more easily/programatically parse the e... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | emhagman |
| hostname | github.com |
| expected-hostname | github.com |
| None | af6de804ceb83ad30bb9b348cdeaccaa30cdcb566762d5e74e21e2bad88885d0 |
| turbo-cache-control | no-preview |
| go-import | github.com/VapiAI/server-sdk-python git https://github.com/VapiAI/server-sdk-python.git |
| octolytics-dimension-user_id | 144965430 |
| octolytics-dimension-user_login | VapiAI |
| octolytics-dimension-repository_id | 858207722 |
| octolytics-dimension-repository_nwo | VapiAI/server-sdk-python |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 858207722 |
| octolytics-dimension-repository_network_root_nwo | VapiAI/server-sdk-python |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 2d980605f0959039ddebcbcf522b072508302977 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width