Skip to content

Commit

Permalink
docs: add docs for error handling (fixes #317)
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 726463667
  • Loading branch information
sararob authored and copybara-github committed Feb 13, 2025
1 parent d96bba2 commit c46a591
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1103,4 +1103,19 @@ print(async_pager[0])
delete_job = client.batches.delete(name=job.name)

delete_job
```

## Error Handling

To handle errors raised by the model service, the SDK provides this [APIError](https://github.com/googleapis/python-genai/blob/main/google/genai/errors.py) class.

```python
try:
client.models.generate_content(
model="invalid-model-name",
contents="What is your name?",
)
except errors.APIError as e:
print(e.code) # 404
print(e.message)
```

0 comments on commit c46a591

Please sign in to comment.