ModelNotAvailableError
together_ai.errors.ModelNotAvailableError
Stack trace
together_ai.errors.ModelNotAvailableError: The requested model 'together-gpt' is not available or currently disabled.
File "app.py", line 42, in generate_response
response = client.chat.completions.create(model="together-gpt", messages=messages)
File "/usr/local/lib/python3.9/site-packages/together_ai/client.py", line 88, in create
raise ModelNotAvailableError("The requested model is not available.") Why it happens
This error occurs when the Together AI service does not have the requested model enabled or the model name is incorrect. It can also happen if the model is temporarily disabled or deprecated by Together AI.
Detection
Catch the ModelNotAvailableError exception when calling the Together AI client and log the model name and error message to detect unavailability before crashing.
Causes & fixes
Incorrect or misspelled model name passed to the Together AI client.
Verify and use the exact model name supported by Together AI, such as 'together-gpt-3.5' or check the official model list.
The requested model is temporarily disabled or deprecated by Together AI.
Check Together AI status or announcements for model availability and switch to an active supported model.
API key or account permissions do not allow access to the requested model.
Ensure your API key has permissions for the model or upgrade your plan if necessary.
Code: broken vs fixed
from together_ai import TogetherAIClient
client = TogetherAIClient(api_key="wrong_key")
response = client.chat.completions.create(model="together-gpt", messages=[{"role": "user", "content": "Hello"}]) # This line raises ModelNotAvailableError import os
from together_ai import TogetherAIClient
client = TogetherAIClient(api_key=os.environ["TOGETHER_API_KEY"])
response = client.chat.completions.create(model="together-gpt-3.5", messages=[{"role": "user", "content": "Hello"}]) # Fixed model name
print(response) Workaround
Wrap the call in try/except ModelNotAvailableError, then fallback to a default supported model or notify the user to retry later.
Prevention
Regularly update your model list from Together AI's official documentation or API metadata to avoid using deprecated or unavailable models.