# Generate a strategy with AI

`POST https://api.cryptohopper.com/v1/strategy/{strategy_id}/aigenerate`

Part of [Strategies](https://www.cryptohopper.com/api-documentation/api-reference/strategies.md) in the Cryptohopper API reference.

Asks an AI model to build a strategy config from a plain-language prompt and returns it. This uses the user's AI credits; the strategy itself is not changed.

When generation fails, for example because the user has too few AI credits, the endpoint still returns HTTP 200, with status 0 and an error message. An unknown or missing model falls back to the default model. To keep the result, save it with Update strategy. Needs a valid access token, but no specific scope.

## Headers

| Name | Type | Required | Description |
|---|---|---|---|
| `access-token` | string | yes | The OAuth access token of the user. |

## Path parameters

| Name | Type | Required | Description |
|---|---|---|---|
| `strategy_id` | string | yes | ID of one of the user's own strategies. |

## Example request

```bash
curl -X POST "https://api.cryptohopper.com/v1/strategy/STRATEGY_ID/aigenerate" \
  -H "access-token: YOUR_ACCESS_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"prompt":"Buy when the RSI on the 15 minute chart is oversold, sell when it is overbought","model":"google/gemini-2.5-flash-lite"}'
```

## Response

Example response (illustrative values):

```json
{
    "data": {
        "status": 1,
        "config": {
            "strategy_config": [
                {
                    "id": "121",
                    "name": "RSI with region crossovers (RSI)",
                    "type": "buy",
                    "params": {
                        "candle_value": {
                            "type": "select",
                            "name": "OHLCV Value",
                            "options": [
                                "open",
                                "close",
                                "high",
                                "low",
                                "volume"
                            ],
                            "default": "close"
                        },
                        "period": {
                            "type": "number",
                            "step": 1,
                            "min": 1,
                            "max": 500,
                            "name": "RSI Period",
                            "default": 14
                        },
                        "oversold": {
                            "type": "number",
                            "step": 0.01,
                            "min": 0,
                            "max": 100,
                            "name": "Oversold threshold",
                            "default": 30
                        },
                        "overbought": {
                            "type": "number",
                            "step": 0.01,
                            "min": 0,
                            "max": 100,
                            "name": "Overbought threshold",
                            "default": 70
                        },
                        "region_type": {
                            "type": "select",
                            "name": "Signal on region",
                            "options": [
                                "in",
                                "out"
                            ],
                            "default": "in"
                        }
                    },
                    "chartperiod": "900",
                    "candle_pattern": 0,
                    "necessary": 1,
                    "keep_signal": 0
                }
            ],
            "minimum_buy_signals": 1,
            "minimum_sell_signals": 1,
            "description": "Buys when the 15 minute RSI moves back out of the oversold region."
        }
    }
}
```

Status codes: 200. Errors return JSON with `status`, `error` and `message`, plus a numeric `code` when the error comes from the API itself rather than the gateway.
