Classes
Async Client
Documentation for using Goodfire’s Async Client API
The Async Client provides asynchronous methods for interacting with Goodfire’s API, allowing for non-blocking operations in asyncio applications.
Using the AsyncClient vs Client
The AsyncClient provides the same functionality as the regular Client but is designed for use in asynchronous applications. Here are the key differences:
- All methods return coroutines that must be awaited
- Streaming responses use
async for
instead of regularfor
loops - The client must be used within an async context
When to Use AsyncClient
Use AsyncClient when:
- Your application uses asyncio
- You need to make concurrent API calls
- You’re building an async web application (e.g., with FastAPI or aiohttp)
- You want to perform other operations while waiting for API responses
Methods
The AsyncClient provides async versions of all the methods available in the regular Client. The parameters and return types are the same, but the methods must be awaited.
Initialization
Example
Basic Async Chat Completion
Concurrent Requests Example
Code
Remember to always run your async code within an async context using asyncio.run()
or within an existing async application framework.