> For the complete documentation index, see [llms.txt](https://docs.agentipy.fun/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.agentipy.fun/tools/fetch-price.md).

# Fetch Price

The `Fetch Price` tool, part of AgentiPy, allows users to fetch the price of a given token in USDC by querying the Jupiter API (`https://api.jup.ag/price/v2`). It's a simple way to get current price data for a specific token mint address on Solana.

## Functionality

This tool is implemented in the `TokenPriceFetcher` class.

### Key Methods:

* `fetch_price(token_id: str) -> str`:
  * Takes a `token_id` (the token mint address as a string) as input.
  * Constructs a URL to query the Jupiter API.
  * Uses `aiohttp` to make an asynchronous GET request to the API.
  * Parses the JSON response to extract the price of the token in USDC.
  * Returns the price as a string.
  * Raises an exception if the API request fails, the response status is not 200, or if price data for the token is not available in the response.

##

**Note:** This tool relies on the public Jupiter API. Availability and rate limits of the API are determined by Jupiter Aggregator. The returned price is typically in USDC.

## Source Code

You can find the source code for this tool on GitHub: <https://github.com/niceberginc/agentipy/blob/main/agentipy/tools/fetch_price.py>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.agentipy.fun/tools/fetch-price.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
