You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+77Lines changed: 77 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -124,6 +124,83 @@ await client.files.create({
124
124
});
125
125
```
126
126
127
+
## Webhook Verification
128
+
129
+
Verifying webhook signatures is _optional but encouraged_.
130
+
131
+
### Parsing webhook payloads
132
+
133
+
For most use cases, you will likely want to verify the webhook and parse the payload at the same time. To achieve this, we provide the method `client.webhooks.unwrap()`, which parses a webhook request and verifies that it was sent by OpenAI. This method will throw an error if the signature is invalid.
134
+
135
+
Note that the `body` parameter must be the raw JSON string sent from the server (do not parse it first). The `.unwrap()` method will parse this JSON for you into an event object after verifying the webhook was sent from OpenAI.
136
+
137
+
```ts
138
+
import { headers } from'next/headers';
139
+
importOpenAIfrom'openai';
140
+
141
+
const client =newOpenAI({
142
+
webhookSecret: process.env.OPENAI_WEBHOOK_SECRET, // env var used by default; explicit here.
In some cases, you may want to verify the webhook separately from parsing the payload. If you prefer to handle these steps separately, we provide the method `client.webhooks.verifySignature()` to _only verify_ the signature of a webhook request. Like `.unwrap()`, this method will throw an error if the signature is invalid.
174
+
175
+
Note that the `body` parameter must be the raw JSON string sent from the server (do not parse it first). You will then need to parse the body after verifying the signature.
176
+
177
+
```ts
178
+
import { headers } from'next/headers';
179
+
importOpenAIfrom'openai';
180
+
181
+
const client =newOpenAI({
182
+
webhookSecret: process.env.OPENAI_WEBHOOK_SECRET, // env var used by default; explicit here.
0 commit comments