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
The Sunrise Python library provides convenient access to the Sunrise REST API from any Python 3.8+
5
+
The Contextual AI Python library provides convenient access to the Contextual AI REST API from any Python 3.8+
6
6
application. The library includes type definitions for all request params and response fields,
7
7
and offers both synchronous and asynchronous clients powered by [httpx](https://github.com/encode/httpx).
8
8
9
9
It is generated with [Stainless](https://www.stainlessapi.com/).
10
10
11
11
## Documentation
12
12
13
-
The REST API documentation can be found on [docs.sunrise.com](https://docs.sunrise.com). The full API of this library can be found in [api.md](api.md).
13
+
The REST API documentation can be found on [docs.contextual.ai](https://docs.contextual.ai). The full API of this library can be found in [api.md](api.md).
While you can provide a `bearer_token` keyword argument,
43
+
While you can provide an `api_key` keyword argument,
44
44
we recommend using [python-dotenv](https://pypi.org/project/python-dotenv/)
45
-
to add `BEARER_TOKEN="My Bearer Token"` to your `.env` file
46
-
so that your Bearer Token is not stored in source control.
45
+
to add `CONTEXTUAL_API_KEY="My API Key"` to your `.env` file
46
+
so that your API Key is not stored in source control.
47
47
48
48
## Async usage
49
49
50
-
Simply import `AsyncSunrise` instead of `Sunrise` and use `await` with each API call:
50
+
Simply import `AsyncContextualAI` instead of `ContextualAI` and use `await` with each API call:
51
51
52
52
```python
53
53
import os
54
54
import asyncio
55
-
fromsunriseimportAsyncSunrise
55
+
fromcontextualimportAsyncContextualAI
56
56
57
-
client =AsyncSunrise(
58
-
bearer_token=os.environ.get("BEARER_TOKEN"), # This is the default and can be omitted
57
+
client =AsyncContextualAI(
58
+
api_key=os.environ.get("CONTEXTUAL_API_KEY"), # This is the default and can be omitted
59
59
)
60
60
61
61
@@ -82,29 +82,29 @@ Typed requests and responses provide autocomplete and documentation within your
82
82
83
83
## Handling errors
84
84
85
-
When the library is unable to connect to the API (for example, due to network connection problems or a timeout), a subclass of `sunrise.APIConnectionError` is raised.
85
+
When the library is unable to connect to the API (for example, due to network connection problems or a timeout), a subclass of `contextual.APIConnectionError` is raised.
86
86
87
87
When the API returns a non-success status code (that is, 4xx or 5xx
88
-
response), a subclass of `sunrise.APIStatusError` is raised, containing `status_code` and `response` properties.
88
+
response), a subclass of `contextual.APIStatusError` is raised, containing `status_code` and `response` properties.
89
89
90
-
All errors inherit from `sunrise.APIError`.
90
+
All errors inherit from `contextual.APIError`.
91
91
92
92
```python
93
-
importsunrise
94
-
fromsunriseimportSunrise
93
+
importcontextual
94
+
fromcontextualimportContextualAI
95
95
96
-
client =Sunrise()
96
+
client =ContextualAI()
97
97
98
98
try:
99
99
client.datastores.create(
100
100
name="name",
101
101
)
102
-
exceptsunrise.APIConnectionError as e:
102
+
exceptcontextual.APIConnectionError as e:
103
103
print("The server could not be reached")
104
104
print(e.__cause__) # an underlying Exception, likely raised within httpx.
105
-
exceptsunrise.RateLimitError as e:
105
+
exceptcontextual.RateLimitError as e:
106
106
print("A 429 status code was received; we should back off a bit.")
107
-
exceptsunrise.APIStatusError as e:
107
+
exceptcontextual.APIStatusError as e:
108
108
print("Another non-200-range status code was received")
109
109
print(e.status_code)
110
110
print(e.response)
@@ -132,10 +132,10 @@ Connection errors (for example, due to a network connectivity problem), 408 Requ
132
132
You can use the `max_retries` option to configure or disable retry settings:
133
133
134
134
```python
135
-
fromsunriseimportSunrise
135
+
fromcontextualimportContextualAI
136
136
137
137
# Configure the default for all requests:
138
-
client =Sunrise(
138
+
client =ContextualAI(
139
139
# default is 2
140
140
max_retries=0,
141
141
)
@@ -152,16 +152,16 @@ By default requests time out after 1 minute. You can configure this with a `time
152
152
which accepts a float or an [`httpx.Timeout`](https://www.python-httpx.org/advanced/#fine-tuning-the-configuration) object:
@@ -218,9 +218,9 @@ datastore = response.parse() # get the object that `datastores.create()` would
218
218
print(datastore.id)
219
219
```
220
220
221
-
These methods return an [`APIResponse`](https://github.com/stainless-sdks/sunrise-python/tree/main/src/sunrise/_response.py) object.
221
+
These methods return an [`APIResponse`](https://github.com/stainless-sdks/sunrise-python/tree/main/src/contextual/_response.py) object.
222
222
223
-
The async client returns an [`AsyncAPIResponse`](https://github.com/stainless-sdks/sunrise-python/tree/main/src/sunrise/_response.py) with the same structure, the only difference being `await`able methods for reading the response content.
223
+
The async client returns an [`AsyncAPIResponse`](https://github.com/stainless-sdks/sunrise-python/tree/main/src/contextual/_response.py) with the same structure, the only difference being `await`able methods for reading the response content.
224
224
225
225
#### `.with_streaming_response`
226
226
@@ -284,10 +284,10 @@ You can directly override the [httpx client](https://www.python-httpx.org/api/#c
0 commit comments