A gas-price selector needs more than a hard-coded list of states: it needs the locations for which price averages are available. With State Gas Price Averages API, you can retrieve those names, use them to populate a selector, and prepare users to request an average price for their chosen state.
What the API returns
State Gas Price Averages API provides a list of available U.S. states and separate endpoints for regular and mid-grade gasoline averages. The available-states endpoint returns location names; it does not return gas prices in the example response.
This is useful for a fuel-cost dashboard, a fleet-planning tool, or an application that lets users select a location before looking up an average. The returned list also includes the District of Columbia, so a location selector should not assume every entry is a state.
Getting started on Zyla API Hub
Create an account on Zyla API Hub, open the State Gas Price Averages API listing, and click Subscribe or Start Free Trial when available. Get your API key from your account and use it as a Bearer token in requests.
Zyla uses subscriptions and quotas rather than pay-per-call billing. The first API offers a 7-day trial or 50 requests; check the API page for current access options and pricing.
Retrieve the available states
The get available states endpoint uses POST and requires no documented request parameters. Send the authorization header without a request body:
curl -s -X POST "https://zylalabs.com/api/6186/state-gas-price-averages-api/8615/get-available-states" \
-H "Authorization: Bearer YOUR_API_KEY"
The listing’s response example begins as follows. It is an excerpt, ending with an ellipsis rather than a complete JSON document:
[
{
"states": [
{
"state_name": "Alaska"
},
{
"state_name": "Alabama"
},
{
"state_name": "Arkansas"
},
{
"state_name": "Arizona"
},
{
"state_name": "California"
},
{
"state_name": "Colorado"
},
{
"state_name": "Connecticut"
},
{
"state_name": "District of Columbia"
},
{
"state_name": "Delaware"
},
{
"state_name": "Florida"
},
{
"state_name": "Georgia"
},
{
"state_name": "Hawaii"
},
{
"state_name": "Iowa"
},
{
"state_name": "Idaho"
},
{
"state_name": "Illinois"
},
{
"state_name": "Indiana"
},
{
"state_name": "Kansas"
},
{
"state_name": "Kentucky"
},
{
"state_name": "Louisiana"
},
{
"state_name": "Massachusetts"
},
{
"state_name": "Maryland"
},
{
"state_name": "Maine"
},
{
"state_name": "Michigan"
},
{
"state_name": "Minnesota"
},
{
"state_name": "Missouri"
},
{
"state_name": "Mississippi"
},
{
"state_name": "Montana"
},
{
"state_name": "North Carolina"
},
{
"state_name": "North Dakota"
},
{
"state_name": "Nebraska"
},
{
"state_name": "New Hampshire"
},
{
"state_name": "New Jersey"
},
{
"state_name": "New Mexico"
},
{
"state_name": "Nevada"
},
{
"state_name": "New York"
},…
In the example, the top-level value is an array. Its first object contains a states array, and each entry has a state_name string. Use that string as the displayed location name; do not rely on the example’s ordering or treat its excerpt as the complete list.
Read the names in Python
This example calls the same endpoint with Python’s standard library. It reads the complete live response, extracts the names, and prints them for use in a selector or another integration.
import json
from urllib.request import Request, urlopen
request = Request(
"https://zylalabs.com/api/6186/state-gas-price-averages-api/8615/get-available-states",
headers={"Authorization": "Bearer YOUR_API_KEY"},
method="POST",
)
with urlopen(request) as response:
payload = json.load(response)
for group in payload:
for state in group["states"]:
print(state["state_name"])
Replace YOUR_API_KEY before running it. In an application, keep the key on the server rather than embedding it in a browser page, and handle request or parsing failures before updating the selector.
Look up a price for a selected state
After a user chooses an available location, the API offers separate POST endpoints for the fuel grades below. Both require a state to be indicated; check the listing for the state parameter’s name and placement before implementing either request.
Regular gasoline
POST https://zylalabs.com/api/6186/state-gas-price-averages-api/8616/get-regular-gas-price
This endpoint provides the average regular gasoline price for a specific state. Its example response uses state and regular_gas_price; the example price is a string containing a dollar sign.
Mid-grade gasoline
POST https://zylalabs.com/api/6186/state-gas-price-averages-api/8617/get-mid-grade-gas-price
This endpoint provides the average mid-grade gasoline price for a specific state. Its example uses state and mid_grade_gas_price, with the price represented as a string without a dollar sign.
Handle the two example formats separately rather than assuming identical response structures or formatting. Confirm the price units and any conversion requirements on the listing before using an average in a cost calculation.
Integration and AI-agent considerations
For a selector, fetch the available locations and display their returned names. If you cache the list to avoid fetching it on every page load, choose a refresh policy appropriate for your application and provide a way to recover if the refresh fails. Check the subscription quota when deciding how often to refresh.
A fleet tool could use the list to limit location choices before a user requests a fuel average. A dashboard could use the same list to populate a filter, then show the selected grade’s result once the price request has been configured.
For an AI-agent workflow, connect an MCP-compatible client using https://mcp.zylalabs.com/mcp?apikey=YOUR_API_KEY. The endpoint works with Claude Code, Cursor, Windsurf, and other MCP-compatible clients. See MCP for access; keep the key-bearing connection URL private.
FAQ
Does the available-states request need a state parameter?
No. The documented request sends a POST with the Bearer authorization header and no request parameters.
Does the available-states response include prices?
The example contains location names under states. Use the separate regular or mid-grade endpoint to request an average price for a selected state.
Can I use the returned names directly in a price request?
The price endpoints use a state from the available-states list. Check the listing for how to provide that state in the request before wiring up the lookup.
Is the example response a complete list?
No. The listing excerpt above ends with an ellipsis. Parse the live response rather than copying the excerpt into your application.
Ready to build the selector? Create a free Zyla account, get an API key, and Start 7-day trial on State Gas Price Averages API. Check the listing for current access options and pricing.
Official API response
[
{
"states": [
{
"state_name": "Alaska"
},
{
"state_name": "Alabama"
},
{
"state_name": "Arkansas"
},
{
"state_name": "Arizona"
},
{
"state_name": "California"
},
{
"state_name": "Colorado"
},
{
"state_name": "Connecticut"
},
{
"state_name": "District of Columbia"
},
{
"state_name": "Delaware"
},
{
"state_name": "Florida"
},
{
"state_name": "Georgia"
},
{
"state_name": "Hawaii"
},
{
"state_name": "Iowa"
},
{
"state_name": "Idaho"
},
{
"state_name": "Illinois"
},
{
"state_name": "Indiana"
},
{
"state_name": "Kansas"
},
{
"state_name": "Kentucky"
},
{
"state_name": "Louisiana"
},
{
"state_name": "Massachusetts"
},
{
"state_name": "Maryland"
},
{
"state_name": "Maine"
},
{
"state_name": "Michigan"
},
{
"state_name": "Minnesota"
},
{
"state_name": "Missouri"
},
{
"state_name": "Mississippi"
},
{
"state_name": "Montana"
},
{
"state_name": "North Carolina"
},
{
"state_name": "North Dakota"
},
{
"state_name": "Nebraska"
},
{
"state_name": "New Hampshire"
},
{
"state_name": "New Jersey"
},
{
"state_name": "New Mexico"
},
{
"state_name": "Nevada"
},
{
"state_name": "New York"
},…
Official API response
[
{
"states": [
{
"state_name": "Alaska"
},
{
"state_name": "Alabama"
},
{
"state_name": "Arkansas"
},
{
"state_name": "Arizona"
},
{
"state_name": "California"
},
{
"state_name": "Colorado"
},
{
"state_name": "Connecticut"
},
{
"state_name": "District of Columbia"
},
{
"state_name": "Delaware"
},
{
"state_name": "Florida"
},
{
"state_name": "Georgia"
},
{
"state_name": "Hawaii"
},
{
"state_name": "Iowa"
},
{
"state_name": "Idaho"
},
{
"state_name": "Illinois"
},
{
"state_name": "Indiana"
},
{
"state_name": "Kansas"
},
{
"state_name": "Kentucky"
},
{
"state_name": "Louisiana"
},
{
"state_name": "Massachusetts"
},
{
"state_name": "Maryland"
},
{
"state_name": "Maine"
},
{
"state_name": "Michigan"
},
{
"state_name": "Minnesota"
},
{
"state_name": "Missouri"
},
{
"state_name": "Mississippi"
},
{
"state_name": "Montana"
},
{
"state_name": "North Carolina"
},
{
"state_name": "North Dakota"
},
{
"state_name": "Nebraska"
},
{
"state_name": "New Hampshire"
},
{
"state_name": "New Jersey"
},
{
"state_name": "New Mexico"
},
{
"state_name": "Nevada"
},
{
"state_name": "New York"
},…