AnyLLM
The AnyLLM class - provider interface with metadata access and reusability
Creating an Instance
AnyLLM.create()
AnyLLM.create()def create(
provider: str | LLMProvider,
api_key: str | None = None,
api_base: str | None = None,
**kwargs: Any,
) -> AnyLLMParameter
Type
Default
Description
from any_llm import AnyLLM
llm = AnyLLM.create("openai", api_key="sk-...")
response = llm.completion(
model="gpt-4.1-mini",
messages=[{"role": "user", "content": "Hello!"}],
)
print(response.choices[0].message.content)Static Methods
AnyLLM.split_model_provider()
AnyLLM.split_model_provider()Parameter
Type
Description
AnyLLM.get_all_provider_metadata()
AnyLLM.get_all_provider_metadata()AnyLLM.get_supported_providers()
AnyLLM.get_supported_providers()Instance Methods
completion() / acompletion()
completion() / acompletion()responses() / aresponses()
responses() / aresponses()messages() / amessages()
messages() / amessages()list_models() / alist_models()
list_models() / alist_models()create_batch() / acreate_batch()
create_batch() / acreate_batch()get_provider_metadata()
get_provider_metadata()Last updated