AI/ML API
Der Einstieg in die AI/ML API ist einfach. Befolgen Sie diese Schritte, um Ihre Integration einzurichten
1. Holen Sie sich Ihren API-Schlüssel​
Um zu beginnen, benötigen Sie einen API-Schlüssel. Sie können Ihren hier erhalten
🔑 Holen Sie sich Ihren API-Schlüssel
2. Entdecken Sie verfügbare Modelle​
Suchen Sie ein anderes Modell? Durchsuchen Sie die vollständige Liste der unterstützten Modelle
📚 Vollständige Liste der Modelle
3. Lesen Sie die Dokumentation​
Für detaillierte Einrichtungsanweisungen und Nutzungsrichtlinien lesen Sie die offizielle Dokumentation
📖 AI/ML API Docs
4. Benötigen Sie Hilfe?​
Wenn Sie Fragen haben, zögern Sie nicht, uns zu kontaktieren. Wir helfen Ihnen gerne weiter! 🚀 Discord
Verwendung​
Sie können aus LLama, Qwen, Flux und über 200 weiteren Open- und Closed-Source-Modellen auf aimlapi.com/models wählen. Zum Beispiel
import litellm
response = litellm.completion(
model="openai/meta-llama/Meta-Llama-3.1-405B-Instruct-Turbo", # The model name must include prefix "openai" + the model name from ai/ml api
api_key="", # your aiml api-key
api_base="https://api.aimlapi.com/v2",
messages=[
{
"role": "user",
"content": "Hey, how's it going?",
}
],
)
Streaming​
import litellm
response = litellm.completion(
model="openai/Qwen/Qwen2-72B-Instruct", # The model name must include prefix "openai" + the model name from ai/ml api
api_key="", # your aiml api-key
api_base="https://api.aimlapi.com/v2",
messages=[
{
"role": "user",
"content": "Hey, how's it going?",
}
],
stream=True,
)
for chunk in response:
print(chunk)
Asynchrone Vervollständigung​
import asyncio
import litellm
async def main():
response = await litellm.acompletion(
model="openai/anthropic/claude-3-5-haiku", # The model name must include prefix "openai" + the model name from ai/ml api
api_key="", # your aiml api-key
api_base="https://api.aimlapi.com/v2",
messages=[
{
"role": "user",
"content": "Hey, how's it going?",
}
],
)
print(response)
if __name__ == "__main__":
asyncio.run(main())
Asynchrones Streaming​
import asyncio
import traceback
import litellm
async def main():
try:
print("test acompletion + streaming")
response = await litellm.acompletion(
model="openai/nvidia/Llama-3.1-Nemotron-70B-Instruct-HF", # The model name must include prefix "openai" + the model name from ai/ml api
api_key="", # your aiml api-key
api_base="https://api.aimlapi.com/v2",
messages=[{"content": "Hey, how's it going?", "role": "user"}],
stream=True,
)
print(f"response: {response}")
async for chunk in response:
print(chunk)
except:
print(f"error occurred: {traceback.format_exc()}")
pass
if __name__ == "__main__":
asyncio.run(main())
Asynchrone Einbettung​
import asyncio
import litellm
async def main():
response = await litellm.aembedding(
model="openai/text-embedding-3-small", # The model name must include prefix "openai" + the model name from ai/ml api
api_key="", # your aiml api-key
api_base="https://api.aimlapi.com/v1", # 👈 the URL has changed from v2 to v1
input="Your text string",
)
print(response)
if __name__ == "__main__":
asyncio.run(main())
Asynchrone Bilderzeugung​
import asyncio
import litellm
async def main():
response = await litellm.aimage_generation(
model="openai/dall-e-3", # The model name must include prefix "openai" + the model name from ai/ml api
api_key="", # your aiml api-key
api_base="https://api.aimlapi.com/v1", # 👈 the URL has changed from v2 to v1
prompt="A cute baby sea otter",
)
print(response)
if __name__ == "__main__":
asyncio.run(main())