Skip to main content
Today we will be making a fun script to text us a nice recommendation for outfits based on the weather every morning. It will look something like this at the end: Weather Recommendation Screenshot This project has 3 main components:
  1. Check the weather using the free OpenMeteo API
  2. Pass the weather info to Telnyx Inference using the model of our choice
  3. Send the recommendation to the user using Telnyx SMS
Let’s get started!

Checking the weather with OpenMeteo

OpenMeteo is a great free API that allows you to retrieve the forecast for the current day. They have a ton of options for what you can retrieve, but for this demo, we will stick with just the temperature and weather code (although feel free to experiment with other things like humidity!). The following functions can be used to retrieve a weather_description that we can feed into our Telnyx Inference model:
It looks like a lot of code, but the majority is just converting the weather codes to a nicely formatted string that the model will be able to understand. Notice also that the longitude and latitude are required to skip the need for an API key, so we will use Chicago’s latitude and longitude, 41.9 and 87.6 for this example.

Getting our recommendation text from Telnyx Inference

Now that we have the current weather, let’s make a call to Telnyx Inference to generate a text to send to our user. There are many state-of-the-art open source models available through the Telnyx API, so for this one we will select GLM-5.2 from Zhipu AI. Let’s write a function to retrieve a good weather recommendation from Telnyx Inference. We will just use the requests library to not add an additional pip requirement, but the Telnyx LLM API is also compatible with the OpenAI Python and JS SDKs, see the OpenAI Migration Guide Here.
Make sure your TELNYX_API_KEY is set in your environment variables so that they can be loaded with os.getenv('TELNYX_API_KEY'). The API spec for chat completions can be found here if you would prefer to use HTTP requests instead of the OpenAI client or want to play around with some of the LLM parameters offered. The output of this function will be a string with our recommendation, for example: “Good morning. Perfect day ahead. Why not try a light, pastel-colored short-sleeved shirt, paired with some beige or light-gray shorts? Add some loafers or sneakers, and you’re all set for a sunny day. Have a great one!”

Sending our text to the user

Great! Now that we have our weather and text recommendation, we can send the text to the user. Sending a message with Telnyx SMS is easy, follow the tutorial here if you have not set up a Telnyx number yet. We can use the following snippet to send a text using Telnyx:

Putting it all together

Now that we have all the pieces in place, let’s run the script! We can use the following sequence to chain everything together:
And we see the following output:
Great work! We now have our script to send the user weather recommendations based on the weather. To improve this, test out different weather attributes such as humidity to influence the outfit recommendations, or adjust the prompt so the model knows what you generally like to wear or what you have in your closet. You could also run this script automatically every day at a certain time using a cronjob or the task scheduler of your choice. Thanks for following along!