> ## Documentation Index
> Fetch the complete documentation index at: https://docs.pan.tech/llms.txt
> Use this file to discover all available pages before exploring further.

# Crear Intent

> POST /v1/intents

Crea y ejecuta un intent DeFi.

## Endpoint

```
POST https://api.pan.tech/v1/intents
```

## Autenticación

<Note>
  Solo API Key. X402 no soportado para operaciones de escritura.
</Note>

## Request

### Body - Lend

```json theme={null}
{
  "walletId": "pan_wallet_abc123",
  "action": "lend",
  "amount": 1000,
  "asset": "USDC",
  "chain": "base"
}
```

### Body - Withdraw

```json theme={null}
{
  "walletId": "pan_wallet_abc123",
  "action": "withdraw",
  "amount": 500,
  "asset": "USDC",
  "chain": "base"
}
```

### Body - Bridge

```json theme={null}
{
  "walletId": "pan_wallet_abc123",
  "action": "bridge",
  "amount": 500,
  "asset": "USDC",
  "fromChain": "ethereum",
  "toChain": "arbitrum"
}
```

### Parámetros

| Campo       | Tipo   | Requerido | Descripción                    |
| ----------- | ------ | --------- | ------------------------------ |
| `walletId`  | string | Si        | ID de la wallet                |
| `action`    | string | Si        | `lend`, `withdraw`, o `bridge` |
| `amount`    | number | Si        | Cantidad en unidades del token |
| `asset`     | string | No        | Token (default: `USDC`)        |
| `chain`     | string | Depende   | Requerido para withdraw        |
| `fromChain` | string | Depende   | Requerido para bridge          |
| `toChain`   | string | Depende   | Requerido para bridge          |

## Response

### 201 Created

```json theme={null}
{
  "id": "intent_xyz789abc123",
  "walletId": "pan_wallet_abc123",
  "status": "planning",
  "action": "lend",
  "amount": 1000,
  "asset": "USDC",
  "executionPlan": {
    "strategy": "single-bridge",
    "targetChain": "base",
    "targetProtocol": "aave",
    "expectedApy": 8.52,
    "steps": [
      {
        "type": "bridge",
        "sequence": 1,
        "from": "arbitrum",
        "to": "base",
        "asset": "USDC",
        "amount": "1000"
      },
      {
        "type": "deposit",
        "sequence": 2,
        "chain": "base",
        "protocol": "aave",
        "amount": "998.50"
      }
    ],
    "estimatedGasUsd": 2.50,
    "estimatedTime": "3-7 min"
  },
  "createdAt": "2024-01-15T10:40:00Z"
}
```

### Estados

| Estado      | Descripción                     |
| ----------- | ------------------------------- |
| `pending`   | Creado, esperando procesamiento |
| `planning`  | Generando plan de ejecución     |
| `executing` | Ejecutando transacciones        |
| `completed` | Completado exitosamente         |
| `failed`    | Error durante ejecución         |

### Errores

| Código | Error               | Descripción          |
| ------ | ------------------- | -------------------- |
| 400    | INVALID\_REQUEST    | Parámetros invalidos |
| 400    | INSUFFICIENT\_FUNDS | Fondos insuficientes |
| 401    | UNAUTHORIZED        | API key inválida     |
| 404    | WALLET\_NOT\_FOUND  | Wallet no existe     |

## Ejemplos

<CodeGroup>
  ```bash cURL - Lend theme={null}
  curl -X POST https://api.pan.tech/v1/intents \
    -H "Authorization: Bearer $PAN_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "walletId": "pan_wallet_abc123",
      "action": "lend",
      "amount": 1000,
      "asset": "USDC"
    }'
  ```

  ```bash cURL - Withdraw theme={null}
  curl -X POST https://api.pan.tech/v1/intents \
    -H "Authorization: Bearer $PAN_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "walletId": "pan_wallet_abc123",
      "action": "withdraw",
      "amount": 500,
      "asset": "USDC",
      "chain": "base"
    }'
  ```

  ```bash cURL - Bridge theme={null}
  curl -X POST https://api.pan.tech/v1/intents \
    -H "Authorization: Bearer $PAN_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "walletId": "pan_wallet_abc123",
      "action": "bridge",
      "amount": 500,
      "asset": "USDC",
      "fromChain": "ethereum",
      "toChain": "arbitrum"
    }'
  ```

  ```typescript SDK - Lend theme={null}
  const intent = await pan.lend({
    walletId: 'pan_wallet_abc123',
    amount: 1000,
    asset: 'USDC'
  });
  ```

  ```typescript SDK - Withdraw theme={null}
  const intent = await pan.withdraw({
    walletId: 'pan_wallet_abc123',
    amount: 500,
    asset: 'USDC',
    chain: 'base'
  });
  ```

  ```typescript SDK - Bridge theme={null}
  const intent = await pan.bridge({
    walletId: 'pan_wallet_abc123',
    amount: 500,
    asset: 'USDC',
    fromChain: 'ethereum',
    toChain: 'arbitrum'
  });
  ```
</CodeGroup>

## Notas

* La ejecución es asincrona. Usa GET /intents/:id para monitorear
* Para `lend`, si no específicas `chain`, pan elige el mejor APY
* Los intents consumen 5 creditos
