Skip to content

Commit 5af4072

Browse files
authored
chore: small update to docs for difference in stateful vs stateless apis (#568)
## Description <!-- What does this PR do? --> ## PR Type <!-- Delete the types that don't apply --!> 📚 Documentation ## Relevant issues <!-- e.g. "Fixes #123" --> ## Checklist - [ ] I have added unit tests that prove my fix/feature works - [ ] New and existing tests pass locally - [ ] Documentation was updated where necessary - [ ] I have read and followed the [contribution guidelines](https://github.com/mozilla-ai/any-llm/blob/main/CONTRIBUTING.md)```
1 parent eb3ec4a commit 5af4072

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

README.md

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -137,23 +137,27 @@ from any_llm import AnyLLM
137137

138138
llm = AnyLLM.create("mistral", api_key="your-mistral-api-key")
139139

140-
response = llm.completion({
141-
"model_id": "mistral-small-latest",
142-
"messages": [{"role": "user", "content": "Hello!"}]
143-
})
140+
response = llm.completion(
141+
model="mistral-small-latest",
142+
messages=[{"role": "user", "content": "Hello!"}]
143+
)
144144

145145
```
146146

147147
#### When to Use Which Approach
148148

149-
**Use Direct API Functions when:**
150-
- Making simple, one-off requests
151-
- Prototyping or quick scripts
152-
- You want the simplest possible interface
149+
**Direct API Functions (`completion`, `acompletion`):**
150+
- Creates a new provider client on each call
151+
- Stateless with no connection reuse between calls
152+
- Minimal code for single requests
153+
- Suitable for: scripts, notebooks, infrequent API calls
154+
155+
**AnyLLM Class (`AnyLLM.create`):**
156+
- Reuses the same provider client across multiple calls
157+
- Connection pooling and client state management
158+
- Suitable for: applications making multiple requests, long-running services
153159

154-
**Use Provider Class when:**
155-
- Building applications that make multiple requests with the same provider
156-
- You want to avoid repeated provider instantiation overhead
160+
Both approaches support identical features (streaming, tools, responses API, etc.). The functional API internally uses the class-based API. Choose based on your code structure and usage patterns
157161

158162
The provider_id should be specified according to the [provider ids supported by any-llm](https://mozilla-ai.github.io/any-llm/providers/).
159163
The `model_id` portion is passed directly to the provider internals: to understand what model ids are available for a provider,

0 commit comments

Comments
 (0)