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

# Examples

> Real-world integration examples for common use cases

# Examples

Practical examples to help you integrate the iNwealth API into your application.

## Simple question

A single-turn question about French legislation:

```bash theme={null}
curl -X POST https://api.inwealth.fr/api/agent \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer sk_live_your_key_here" \
  -d '{
    "messages": [
      {"role": "user", "content": "What are the tax brackets in France for 2025?"}
    ],
    "session_id": "demo-001",
    "residence": "fr",
    "language": "en"
  }'
```

<Tip>
  For simple factual questions, leave `effort` and `extended_thinking` at their defaults to minimize token usage.
</Tip>

## Multi-turn conversation

The API is stateless — send the full conversation history each time. Reuse the same `session_id` to benefit from prompt caching.

```bash theme={null}
# Turn 1
curl -X POST https://api.inwealth.fr/api/agent \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer sk_live_your_key_here" \
  -d '{
    "messages": [
      {"role": "user", "content": "What is the PER in France?"}
    ],
    "session_id": "demo-multi-001",
    "residence": "fr",
    "language": "en"
  }'
```

```bash theme={null}
# Turn 2 — include the full history
curl -X POST https://api.inwealth.fr/api/agent \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer sk_live_your_key_here" \
  -d '{
    "messages": [
      {"role": "user", "content": "What is the PER in France?"},
      {"role": "assistant", "content": "The PER (Plan d'\''Epargne Retraite) is a retirement savings plan introduced in 2019..."},
      {"role": "user", "content": "What are the tax deduction limits for 2025?"}
    ],
    "session_id": "demo-multi-001",
    "residence": "fr",
    "language": "en"
  }'
```

<Note>
  In the `assistant` message, include the **full text** that the agent returned (all concatenated `delta.content` values). Do not include metadata or thinking data.
</Note>

## Cross-border scenario

For complex cross-border questions, enable `extended_thinking` and use a higher `effort` level:

```bash theme={null}
curl -X POST https://api.inwealth.fr/api/agent \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer sk_live_your_key_here" \
  -d '{
    "messages": [
      {"role": "user", "content": "I am a French tax resident with a Swiss employer. How is my salary taxed? What about the double taxation treaty?"}
    ],
    "session_id": "demo-crossborder-001",
    "residence": "fr",
    "language": "en",
    "extended_thinking": true,
    "effort": "high"
  }'
```

## Multilingual support

The agent responds in the requested `language`, regardless of the user's question language or `residence`:

```bash theme={null}
# Question in English, response in German, about Swiss taxation
curl -X POST https://api.inwealth.fr/api/agent \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer sk_live_your_key_here" \
  -d '{
    "messages": [
      {"role": "user", "content": "How does the Swiss wealth tax work?"}
    ],
    "session_id": "demo-lang-001",
    "residence": "ch",
    "language": "de"
  }'
```

## Token-optimized integration

Best practices to minimize token consumption in production:

```json theme={null}
{
  "messages": [
    {"role": "user", "content": "Your question here"}
  ],
  "session_id": "user-123-conversation-456",
  "residence": "fr",
  "effort": "low"
}
```

**Key optimizations:**

1. **Reuse `session_id`** — keep the same ID across turns in a conversation. Prompt caching can reduce token costs by up to 90%.
2. **Set `effort` explicitly** — use `"low"` or `"medium"` for straightforward questions. Reserve `"high"` and `"max"` for complex scenarios.
3. **Trim long histories** — for conversations beyond 10 turns, consider sending only the last 4-6 turns to keep input tokens low.
4. **Use `extended_thinking` selectively** — only for questions involving multiple jurisdictions or complex wealth planning.
