Skip to content

Commit ad7a7a2

Browse files
authored
Update README.md
1 parent 54de7e7 commit ad7a7a2

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

README.md

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const completion = await openai.createCompletion("davinci", {
2828
console.log(completion.data.choices[0].text);
2929
```
3030

31-
Check out the [full API documentation](https://beta.openai.com/docs/api-reference?lang=javascript) for examples of all the available functions.
31+
Check out the [full API documentation](https://beta.openai.com/docs/api-reference?lang=node.js) for examples of all the available functions.
3232

3333
### Request options
3434

@@ -51,6 +51,26 @@ const completion = await openai.createCompletion(
5151
);
5252
```
5353

54+
### Error handling
55+
56+
API requests can potentially return errors due to invalid inputs or other issues. These errors can be handled with a `try...catch` statement, and the error details can be found in either `error.response` or `error.message`:
57+
58+
```javascript
59+
try {
60+
const completion = await openai.createCompletion("davinci", {
61+
prompt: "Hello world",
62+
});
63+
console.log(completion.data.choices[0].text);
64+
} catch (error) {
65+
if (error.response) {
66+
console.log(error.response.status);
67+
console.log(error.response.data);
68+
} else {
69+
console.log(error.message);
70+
}
71+
}
72+
```
73+
5474
## Thanks
5575

56-
Thank you to [ceifa](https://github.com/ceifa) for creating and maintaining the original unofficial `openai` npm package before we released this official library!
76+
Thank you to [ceifa](https://github.com/ceifa) for creating and maintaining the original unofficial `openai` npm package before we released this official library! ceifa's original package has been renamed to [gpt-x](https://www.npmjs.com/package/gpt-x).

0 commit comments

Comments
 (0)