LiteLLM provides a unified interface to call 100+ language models using the OpenAI format. AnyAPI integrates seamlessly with LiteLLM, allowing you to access all AnyAPI models through LiteLLM’s standardized interface.
from litellm import completionimport os# Set your AnyAPI keyos.environ["ANYAPI_API_KEY"] = "your-anyapi-key"# Call any AnyAPI model using LiteLLMresponse = completion( model="anyapi/gpt-4o", messages=[{"role": "user", "content": "Hello, how are you?"}], api_base="https://api.anyapi.ai/v1")print(response.choices[0].message.content)
from litellm import completiondef stream_response(): response = completion( model="anyapi/gpt-4o", messages=[{"role": "user", "content": "Write a long story about AI"}], stream=True ) for chunk in response: if chunk.choices[0].delta.content: print(chunk.choices[0].delta.content, end="", flush=True)stream_response()
from litellm import completion# Automatic retries on failureresponse = completion( model="anyapi/gpt-4o", messages=[{"role": "user", "content": "Hello"}], num_retries=3, # Retry up to 3 times timeout=30 # 30 second timeout)