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
We provide support for streaming responses using Server Side Events (SSE).
147
+
148
+
```python
149
+
from perplexity import Perplexity
150
+
151
+
client = Perplexity()
152
+
153
+
stream = client.chat.completions.create(
154
+
messages=[
155
+
{
156
+
"role": "user",
157
+
"content": "What is the capital of France?",
158
+
}
159
+
],
160
+
model="sonar",
161
+
stream=True,
162
+
)
163
+
for stream_chunk in stream:
164
+
print(stream_chunk.id)
165
+
```
166
+
167
+
The async client uses the exact same interface.
168
+
169
+
```python
170
+
from perplexity import AsyncPerplexity
171
+
172
+
client = AsyncPerplexity()
173
+
174
+
stream =await client.chat.completions.create(
175
+
messages=[
176
+
{
177
+
"role": "user",
178
+
"content": "What is the capital of France?",
179
+
}
180
+
],
181
+
model="sonar",
182
+
stream=True,
183
+
)
184
+
asyncfor stream_chunk in stream:
185
+
print(stream_chunk.id)
186
+
```
187
+
144
188
## Using types
145
189
146
190
Nested request parameters are [TypedDicts](https://docs.python.org/3/library/typing.html#typing.TypedDict). Responses are [Pydantic models](https://docs.pydantic.dev) which also provide helper methods for things like:
@@ -159,7 +203,7 @@ from perplexity import Perplexity
0 commit comments