> For the complete documentation index, see [llms.txt](https://docs.madjik.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.madjik.io/integration-guides/ai-integration.md).

# Using Madjik API for AI

Integrate Madjik's crypto market intelligence into your AI applications for enhanced decision-making and analysis.

## Overview

Madjik API provides real-time and historical crypto market data optimized for AI consumption:

* **Structured JSON responses** ready for AI processing
* **Normalized metrics** (0-100 scales) for easy interpretation
* **Rich context** with related hypotheses and trading signals
* **Low latency** for real-time AI applications

## Use Cases

### 1. AI Trading Assistants

Build AI assistants that provide trading insights:

```python
import requests
import openai

def get_market_context():
    metrics = ["ME10030", "ME10014", "ME10016"]  # Sentiment, Funding, Liquidation
    context = []
    for m in metrics:
        resp = requests.get(
            f"https://api.madjik.io/v1/metrics/{m.lower()}",
            headers={"Authorization": "Bearer YOUR_API_KEY"}
        )
        context.append(resp.json())
    return context

# Feed to AI
context = get_market_context()
response = openai.chat.completions.create(
    model="gpt-4",
    messages=[
        {"role": "system", "content": "You are a crypto trading assistant."},
        {"role": "user", "content": f"Given this market data: {context}, what's your analysis?"}
    ]
)
```

### 2. Sentiment Analysis Enhancement

Combine Madjik sentiment with your own NLP:

```python
# Get Madjik sentiment baseline
madjik_sentiment = requests.get(
    "https://api.madjik.io/v1/metrics/me10030",
    headers={"Authorization": "Bearer YOUR_API_KEY"}
).json()

# Compare with your AI sentiment
your_sentiment = your_nlp_model.analyze(tweets)

# Weighted combination
combined = 0.6 * madjik_sentiment['value'] + 0.4 * your_sentiment
```

### 3. Risk Assessment AI

```python
def ai_risk_assessment():
    risk_metrics = {
        "liquidation": "ME10016",
        "volatility": "ME10018",
        "counterparty": "ME10005"
    }
    
    risks = {}
    for name, metric_id in risk_metrics.items():
        resp = requests.get(
            f"https://api.madjik.io/v1/metrics/{metric_id.lower()}",
            headers={"Authorization": "Bearer YOUR_API_KEY"}
        )
        risks[name] = resp.json()['value']
    
    # AI interprets risk levels
    return ai_model.assess_risk(risks)
```

## Best Practices

1. **Cache responses** - Reduce API calls, metrics update every 5 minutes
2. **Batch requests** - Request multiple metrics in parallel
3. **Handle errors gracefully** - AI should work with partial data
4. **Provide context** - Include metric descriptions in AI prompts

## Related Metrics for AI

| Metric  | Best For                    |
| ------- | --------------------------- |
| ME10030 | Sentiment analysis input    |
| ME10016 | Risk assessment             |
| ME10010 | Whale behavior prediction   |
| ME10014 | Market positioning analysis |

## See Also

* [ML Integration Guide](/integration-guides/ml-integration.md)
* [A2A Integration Guide](/integration-guides/a2a-integration.md)
* [All Metrics](https://github.com/madjik-io/madjik-api-docs/blob/main/metrics/README.md)


---

# 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.madjik.io/integration-guides/ai-integration.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.
