# How to Get Token Prices Using AutoHedge’s Jupiter Integration

> Learn to get token prices with AutoHedge's Jupiter integration. Use the get_token_price function with Solana mint addresses for USD prices via Jupiter's Price API V3.

- Repository: [Swarms/AutoHedge](https://github.com/The-Swarm-Corporation/AutoHedge)
- Tags: how-to-guide
- Published: 2026-09-09

---

**Use the `get_token_price` function in [`autohedge/tools/jupiter_price.py`](https://github.com/The-Swarm-Corporation/AutoHedge/blob/main/autohedge/tools/jupiter_price.py) to fetch USD‑denominated prices from Jupiter’s Price API V3 by passing a Solana mint address or list of addresses.**

AutoHedge provides a lightweight Python wrapper around Jupiter’s pricing infrastructure, enabling seamless retrieval of real‑time token valuations within algorithmic trading agents and CLI workflows. According to the The‑Swarm‑Corporation/AutoHedge source code, the integration handles HTTP request construction, optional API key authentication, and JSON response parsing automatically. You can invoke the tool directly from custom scripts or through the centralized tool registry that exposes it to the broader AutoHedge framework.

## Locating the Jupiter Price Implementation

The core functionality resides in [`autohedge/tools/jupiter_price.py`](https://github.com/The-Swarm-Corporation/AutoHedge/blob/main/autohedge/tools/jupiter_price.py). The module implements `get_token_price`, a synchronous helper that constructs a GET request to `https://api.jup.ag/price/v3`. The function accepts either a single mint address string or a list of strings, passing them to the API via the `ids` query parameter.

Under the hood, the wrapper uses `httpx` for transport and `loguru` for structured logging. It returns a JSON‑encoded string mapping each requested mint to an object containing at minimum:

- **`decimals`** – Token decimal precision
- **`usdPrice`** – Current USD price
- **`blockId`** – Reference block height (optional)
- **`priceChange24h`** – 24‑hour price delta (optional)

## Authentication and API Key Setup

While Jupiter’s public endpoints work without authentication, higher rate limits require an API key. AutoHedge supports this through environment variable injection.

1. Add your key to a `.env` file in the project root:

```dotenv
JUPITER_API_KEY=your_jupiter_api_key_here

```

2. Load the environment before calling price functions:

```python
from autohedge.env_loader import load_env

load_env()  # Reads .env and populates os.environ

```

When `JUPITER_API_KEY` is present, `get_token_price` automatically injects it as the `x‑api‑key` header. This logic is handled by the loader defined in [`autohedge/env_loader.py`](https://github.com/The-Swarm-Corporation/AutoHedge/blob/main/autohedge/env_loader.py).

## Fetching Token Prices

### Single Token Lookup

Pass a base58-encoded mint address string to retrieve the current valuation for one token.

```python
from autohedge.env_loader import load_env
from autohedge.tools.jupiter_price import get_token_price

load_env()

sol_mint = "So11111111111111111111111111111111111111112"
price_json = get_token_price(sol_mint)
print(price_json)

# {"So11111111111111111111111111111111111111112": {"decimals": 9, "usdPrice": 20.13, ...}}

```

### Batch Price Requests

Supply a list of mint strings to query multiple tokens in a single HTTP round‑trip.

```python
from autohedge.env_loader import load_env
from autohedge.tools.jupiter_price import get_token_price

load_env()

mints = [
    "So11111111111111111111111111111111111111112",   # Wrapped SOL

    "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",   # USDC

]

price_json = get_token_price(mints)
print(price_json)

# Returns a JSON object with keys for each mint

```

### Discovering Tokens Before Pricing

If you do not know the exact mint address, use the companion search utility in [`autohedge/tools/jupiter_search.py`](https://github.com/The-Swarm-Corporation/AutoHedge/blob/main/autohedge/tools/jupiter_search.py) to resolve symbols to mints first.

```python
from autohedge.env_loader import load_env
from autohedge.tools.jupiter_search import search_tokens
from autohedge.tools.jupiter_price import get_token_price
import json

load_env()

search_result = search_tokens("USDC")
tokens = json.loads(search_result)
usdc_mint = tokens[0]["id"]

price = get_token_price(usdc_mint)
print(price)

```

## Error Handling and Edge Cases

The wrapper raises **`httpx.HTTPError`** for any non‑2xx response or network failure, logging a descriptive error message via `loguru` before propagating the exception. If you pass an empty string or empty list to `get_token_price`, the function returns an empty JSON object (`{}`) immediately without hitting the API.

## Integration with AutoHedge’s Tool Registry

For agent‑based workflows, the price lookup is registered in [`autohedge/tools/tools_registry.py`](https://github.com/The-Swarm-Corporation/AutoHedge/blob/main/autohedge/tools/tools_registry.py). This registration exposes `get_token_price` to the CLI and autonomous Swarm agents, allowing price checks to be triggered as discrete tool calls within larger hedge‑strategy pipelines.

## Summary

- **[`autohedge/tools/jupiter_price.py`](https://github.com/The-Swarm-Corporation/AutoHedge/blob/main/autohedge/tools/jupiter_price.py)** contains the `get_token_price` function that queries Jupiter’s Price API V3.
- Pass a single mint address or a list of addresses; the function returns a JSON string with `usdPrice` and `decimals`.
- Set `JUPITER_API_KEY` in your `.env` file and call `load_env()` from [`autohedge/env_loader.py`](https://github.com/The-Swarm-Corporation/AutoHedge/blob/main/autohedge/env_loader.py) to enable authenticated requests.
- Use **`search_tokens`** from [`autohedge/tools/jupiter_search.py`](https://github.com/The-Swarm-Corporation/AutoHedge/blob/main/autohedge/tools/jupiter_search.py) to resolve token symbols to mint addresses before pricing.
- Empty inputs return `{}`; HTTP errors raise `httpx.HTTPError`.

## Frequently Asked Questions

### Do I need a Jupiter API key to use AutoHedge's price lookup?

No, the basic price functionality works without an API key, but Jupiter imposes stricter rate limits on unauthenticated requests. For production usage or high‑frequency polling, set `JUPITER_API_KEY` in your environment.

### What format does the mint address need to be in?

Provide standard Solana base58‑encoded mint addresses as Python strings. The wrapper passes these directly to the `ids` query parameter without transformation.

### How do I handle rate limits when fetching AutoHedge Jupiter token prices?

If you encounter 429 errors, ensure you have loaded a valid `JUPITER_API_KEY` via `load_env()`. Consider adding client‑side throttling or caching layers around `get_token_price` to avoid exceeding Jupiter’s quotas.

### Can I fetch prices for multiple tokens in one call?

Yes. Pass a list of mint address strings to `get_token_price`; the wrapper batches them into a single HTTP request to `api.jup.ag/price/v3` and returns a consolidated JSON object containing price data for all requested tokens.