# POST /api/agent
Source: https://docs.inwealth.fr/api-reference/agent
POST https://api.inwealth.fr/api/agent
Send a message to the AI wealth intelligence agent
# Agent
Send a conversation to the iNwealth AI agent and receive a streaming response.
## Request
Conversation history.
`"user"` for the end-user's message, `"assistant"` for previous AI responses. First message is always `"user"`. Include previous turns to maintain conversation context.
Message text
Unique session identifier (client-side). Reuse the same ID for a conversation to benefit from Anthropic's prompt caching.
Country code for the end-user's tax residence. The agent adapts its answers to local legislation.
Supported: `fr`, `ch`, `it`, `be`, `lu`, `de`, `es`, `pt`, `gb`, `mc`, `gr`, `ad`, `nl`, `us`, `mu`, `ma`, `intl`
Response language. Supported: `fr`, `en`, `de`, `es`, `it`, `pt`
Enable Claude's native extended thinking mode. The agent reasons explicitly before answering — recommended for complex or cross-border questions.
Analysis depth. Controls how deeply the agent analyzes the question.
Values: `low`, `medium`, `high`, `max`, or `null` (auto — the agent decides based on complexity).
## Example request
```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": "Compare taxation of stock options in France vs Switzerland"}
],
"session_id": "session-001",
"residence": "fr",
"language": "en",
"extended_thinking": true,
"effort": "high"
}'
```
## Response
The response is a **streaming SSE** (`text/event-stream`) with five event types:
| Event | Description |
| --------------- | ----------------------------------------------------------------- |
| `delta` | Text fragment (content or thinking) — append to your display |
| `metadata` | Metadata about the response (sources, markers) |
| `done` | End of stream with final message |
| `error` | Error during streaming (rate limit, internal error) |
| `clarification` | Clarifying questions before answering — collect user input (V170) |
```
event: delta
data: {"type": "delta", "delta": {"content": "Stock options are taxed differently "}}
event: delta
data: {"type": "delta", "delta": {"content": "in France and Switzerland..."}}
event: metadata
data: {"type": "metadata", "data": {"markers": [...]}}
event: done
data: {"type": "done", "final_message": {"role": "assistant", "content": "..."}}
```
When `extended_thinking` is enabled, delta events can also contain thinking data:
```
event: delta
data: {"type": "delta", "delta": {"thinking": "Analyzing cross-border implications...", "phase": "RECHERCHE", "step": "Exit tax treaty provisions"}}
```
## Error responses
| Status | Meaning |
| ------ | ------------------------------------------ |
| `200` | OK — SSE stream |
| `401` | Invalid or revoked API key |
| `400` | Invalid parameters (e.g. bad effort value) |
| `422` | Missing required fields |
| `429` | Daily token quota exceeded |
# GET /health
Source: https://docs.inwealth.fr/api-reference/health
GET https://api.inwealth.fr/health
Check API availability and status
# Health Check
Verify that the iNwealth API is running and responsive. No authentication required.
## Example request
```bash theme={null}
curl https://api.inwealth.fr/health
```
## Response
```json theme={null}
{
"status": "healthy",
"timestamp": "2026-03-08T14:30:00+00:00"
}
```
## Fields
| Field | Type | Description |
| ----------- | -------- | ------------------------------------- |
| `status` | `string` | `"healthy"` if the service is running |
| `timestamp` | `string` | Current server time (ISO 8601) |
The first request after an idle period may take a few extra seconds as the container warms up. Schedule periodic health checks to keep the container warm.
# Authentication
Source: https://docs.inwealth.fr/authentication
How to authenticate with the iNwealth API
# Authentication
The iNwealth API uses **API keys** for authentication. Each organization receives a unique key at onboarding.
## API Key format
```
sk_live_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
```
* Prefix: `sk_live_`
* 32 hex characters (128 bits of entropy)
* Shown **once** at generation — store it securely
* Hashed with SHA-256 server-side (never stored in plaintext)
## Usage
Include your API key in the `Authorization` header of every request:
```bash theme={null}
Authorization: Bearer sk_live_your_key_here
```
## Security best practices
Never expose your API key in client-side code (browser, mobile app). Always call the iNwealth API from your backend.
* Store your key in environment variables or a secrets manager
* Rotate keys periodically by requesting a new one
* If a key is compromised, contact us immediately — we can revoke it instantly
## Error responses
| Status | Meaning |
| ------ | -------------------------- |
| `401` | Invalid or revoked API key |
| `429` | Daily token quota exceeded |
# Error Handling
Source: https://docs.inwealth.fr/guides/errors
How to handle errors from the iNwealth API
# Error Handling
The iNwealth API returns errors in two ways depending on when they occur:
* **Before streaming starts** — standard HTTP JSON errors
* **During streaming** — SSE error events
## HTTP errors
These are returned as standard JSON responses before any streaming begins.
### 401 — Authentication failed
```json theme={null}
{
"detail": "Authentification requise"
}
```
Causes:
* Missing `Authorization` header
* Invalid or revoked API key
* Malformed Bearer token
### 400 — Invalid parameters
```json theme={null}
{
"detail": "Invalid effort: xyz. Must be one of ['low', 'medium', 'high', 'max']"
}
```
Returned when a parameter has an invalid value (e.g. unsupported `effort` level).
### 422 — Missing required fields
```json theme={null}
{
"detail": [
{
"type": "missing",
"loc": ["body", "messages"],
"msg": "Field required"
}
]
}
```
Returned when required fields (`messages`, `session_id`) are missing or have the wrong type.
## SSE error events
Some errors occur **after the stream has started** (HTTP 200 already sent). These are delivered as SSE events:
### 429 — Rate limit exceeded
```
event: error
data: {"type": "error", "data": {"error": "Limite quotidienne organisation atteinte (1,000,000 tokens). Reset dans 3h42.", "error_type": "RateLimitExceeded"}}
```
Your organization's daily token quota has been exhausted. The error message includes the time until reset (midnight UTC).
### 500 — Internal error
```
event: error
data: {"type": "error", "data": {"error": "Erreur interne du serveur"}}
```
An unexpected server-side error occurred during response generation. If this persists, contact your account manager.
## Handling errors in code
### JavaScript
```javascript theme={null}
const response = await fetch("https://api.inwealth.fr/api/agent", {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": "Bearer sk_live_your_key_here"
},
body: JSON.stringify({
messages: [{ role: "user", content: "Your question" }],
session_id: "session-001"
})
});
// Handle HTTP errors (401, 400, 422)
if (!response.ok) {
const error = await response.json();
console.error(`HTTP ${response.status}:`, error.detail);
return;
}
// Handle SSE stream (including SSE error events)
const reader = response.body.getReader();
const decoder = new TextDecoder();
while (true) {
const { done, value } = await reader.read();
if (done) break;
const chunk = decoder.decode(value);
for (const line of chunk.split("\n")) {
if (!line.startsWith("data: ")) continue;
const data = JSON.parse(line.slice(6));
if (data.type === "error") {
// SSE error (429 rate limit, 500 internal)
console.error(data.data.error);
if (data.data.error_type === "RateLimitExceeded") {
// Wait until quota resets at midnight UTC
}
return;
}
if (data.type === "delta" && data.delta?.content) {
// Normal delta — append to display
}
}
}
```
### Python
```python theme={null}
import httpx
import json
with httpx.stream(
"POST",
"https://api.inwealth.fr/api/agent",
headers={"Authorization": "Bearer sk_live_your_key_here"},
json={
"messages": [{"role": "user", "content": "Your question"}],
"session_id": "session-001",
},
) as response:
# Handle HTTP errors
if response.status_code != 200:
print(f"HTTP {response.status_code}: {response.read()}")
else:
# Handle SSE stream
for line in response.iter_lines():
if not line.startswith("data: "):
continue
data = json.loads(line[6:])
if data.get("type") == "error":
print(f"SSE error: {data['data']['error']}")
break
```
## Summary
| Code | Type | When | Format |
| ----- | --------- | ------------- | --------------------------------------- |
| `401` | HTTP | Before stream | `{"detail": "..."}` |
| `400` | HTTP | Before stream | `{"detail": "..."}` |
| `422` | HTTP | Before stream | `{"detail": [...]}` |
| `429` | SSE event | During stream | `event: error` with `RateLimitExceeded` |
| `500` | SSE event | During stream | `event: error` |
# Examples
Source: https://docs.inwealth.fr/guides/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"
}'
```
For simple factual questions, leave `effort` and `extended_thinking` at their defaults to minimize token usage.
## 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"
}'
```
In the `assistant` message, include the **full text** that the agent returned (all concatenated `delta.content` values). Do not include metadata or thinking data.
## 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.
# Parameters
Source: https://docs.inwealth.fr/guides/parameters
Configure the agent's behavior with request parameters
# Parameters
The `/api/agent` endpoint accepts several optional parameters to customize the agent's behavior.
## `residence` — Jurisdiction
Country code of the end-user's fiscal residence. The agent adapts its answers to local legislation.
| Code | Country |
| ------ | ---------------- |
| `fr` | France (default) |
| `ch` | Switzerland |
| `it` | Italy |
| `be` | Belgium |
| `lu` | Luxembourg |
| `de` | Germany |
| `es` | Spain |
| `pt` | Portugal |
| `gb` | United Kingdom |
| `mc` | Monaco |
| `gr` | Greece |
| `ad` | Andorra |
| `nl` | Netherlands |
| `us` | United States |
| `mu` | Mauritius |
| `ma` | Morocco |
| `intl` | International |
## `language` — Response language
The language the agent responds in.
| Code | Language |
| ---- | ---------------- |
| `fr` | French (default) |
| `en` | English |
| `de` | German |
| `es` | Spanish |
| `it` | Italian |
| `pt` | Portuguese |
`residence` and `language` are independent. A user residing in Switzerland (`residence: "ch"`) can receive answers in English (`language: "en"`).
## `extended_thinking` — Deep reasoning
Activates Claude's native extended thinking mode.
| Value | Behavior |
| ------- | -------------------------------------------------------------------------------------------- |
| `false` | Fast response (default) |
| `true` | The agent reasons step-by-step before answering — better for complex, cross-border questions |
Extended thinking uses more tokens but produces significantly better answers for complex cross-border scenarios.
## `effort` — Analysis depth
Controls how deeply the agent analyzes the question.
| Value | Behavior |
| ---------- | --------------------------------------------------------------- |
| `null` | Auto — the agent decides based on question complexity (default) |
| `"low"` | Concise answer, minimal analysis |
| `"medium"` | Detailed answer, moderate analysis |
| `"high"` | In-depth analysis, broad source coverage |
| `"max"` | Exhaustive analysis, all relevant sources |
## Example: complex cross-border query
```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 moving from France to Switzerland. How are my stock options taxed during the transition?"}
],
"session_id": "session-crossborder",
"residence": "fr",
"language": "en",
"extended_thinking": true,
"effort": "max"
}'
```
# Rate Limits & Quotas
Source: https://docs.inwealth.fr/guides/rate-limits
Understanding your organization's usage limits
# Rate Limits & Quotas
Each organization has a **daily token quota** that resets at midnight UTC.
## How it works
* Every request consumes **input tokens** (your message + conversation history) and **output tokens** (the agent's response)
* Both are counted against your daily limit
* When the limit is reached, subsequent requests return a `429` error with the time until reset
## Error response
When your quota is exceeded, the API returns an SSE error event:
```
event: error
data: {"type": "error", "data": {"error": "Limite quotidienne organisation atteinte (1,000,000 tokens). Reset dans 3h42.", "error_type": "RateLimitExceeded"}}
```
## Monitoring usage
Contact your iNwealth account manager to:
* Check your current consumption
* Adjust your daily token limit
* Get usage reports
## Tips to optimize token usage
Use `"low"` or `"medium"` effort for simple questions. Reserve `"high"` and `"max"` for complex cross-border scenarios.
Only send relevant conversation history in `messages`. Trim older turns when the conversation gets long.
Same `session_id` across turns enables prompt caching — up to 90% token savings on multi-turn conversations.
Only enable `extended_thinking` for questions that truly need deep reasoning.
# Streaming SSE
Source: https://docs.inwealth.fr/guides/streaming
How to consume the real-time streaming response
# Streaming SSE
The iNwealth API returns responses as **Server-Sent Events** (SSE). This allows you to display the answer progressively as it's generated, just like ChatGPT or Claude.
## Event types
| Event | Description |
| --------------- | ---------------------------------------------------------------------------- |
| `delta` | Text or thinking fragment — append to your display |
| `metadata` | Metadata (sources, markers) |
| `done` | Stream complete with final message |
| `error` | Error during streaming |
| `clarification` | Interactive clarifying questions — pause stream, collect user answers (V170) |
## Raw SSE format
```
event: delta
data: {"type": "delta", "delta": {"content": "The Plan d'Epargne "}}
event: delta
data: {"type": "delta", "delta": {"content": "Retraite (PER) offers "}}
event: delta
data: {"type": "delta", "delta": {"content": "several tax advantages..."}}
event: metadata
data: {"type": "metadata", "data": {"markers": [...]}}
event: done
data: {"type": "done", "final_message": {"role": "assistant", "content": "The Plan d'Epargne Retraite (PER) offers several tax advantages..."}}
```
### Extended thinking deltas
When `extended_thinking` is enabled, delta events may include thinking data instead of content:
```
event: delta
data: {"type": "delta", "delta": {"thinking": "Analyzing PER tax deductions...", "phase": "RECHERCHE", "step": "Tax deduction limits"}}
```
| Field | Description |
| --------------------- | ---------------------------------------------------------------------------- |
| `delta.content` | Text fragment of the response |
| `delta.thinking` | Thinking fragment (when `extended_thinking` is on) |
| `delta.phase` | Current thinking phase: `"RECHERCHE"` or `"RAISONNEMENT"` |
| `delta.step` | Current thinking step (human-readable) |
| `delta.content_reset` | If `true`, clear accumulated content (intermediate text before final answer) |
## JavaScript (fetch + ReadableStream)
```javascript theme={null}
const response = await fetch("https://api.inwealth.fr/api/agent", {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": "Bearer sk_live_your_key_here"
},
body: JSON.stringify({
messages: [{ role: "user", content: "Tax advantages of PER?" }],
session_id: "session-001"
})
});
const reader = response.body.getReader();
const decoder = new TextDecoder();
let fullText = "";
while (true) {
const { done, value } = await reader.read();
if (done) break;
const chunk = decoder.decode(value);
for (const line of chunk.split("\n")) {
if (!line.startsWith("data: ")) continue;
const data = JSON.parse(line.slice(6));
if (data.type === "delta" && data.delta?.content) {
fullText += data.delta.content;
updateDisplay(fullText); // Update your UI progressively
} else if (data.type === "delta" && data.delta?.content_reset) {
fullText = ""; // Clear intermediate text before final answer
} else if (data.type === "error") {
console.error(data.data.error);
break;
}
}
}
```
## Python (httpx)
```python theme={null}
import httpx
import json
with httpx.stream(
"POST",
"https://api.inwealth.fr/api/agent",
headers={"Authorization": "Bearer sk_live_your_key_here"},
json={
"messages": [{"role": "user", "content": "Tax advantages of PER?"}],
"session_id": "session-001",
},
) as response:
full_text = ""
for line in response.iter_lines():
if not line.startswith("data: "):
continue
data = json.loads(line[6:])
if data.get("type") == "delta":
content = data.get("delta", {}).get("content", "")
if content:
full_text += content
print(content, end="", flush=True)
elif data.get("type") == "error":
print(f"\nError: {data['data']['error']}")
break
```
## Multi-turn conversation
The API is **stateless**. Send the full conversation history in `messages`:
```json theme={null}
{
"messages": [
{"role": "user", "content": "What is the PER?"},
{"role": "assistant", "content": "The PER is a retirement savings plan..."},
{"role": "user", "content": "What about for non-residents?"}
],
"session_id": "session-001",
"residence": "ch"
}
```
Reuse the same `session_id` across turns to benefit from Anthropic's prompt caching, reducing latency and token costs.
For long conversations (12+ turns), the API automatically optimizes the conversation history to stay within model limits. The most recent messages are always preserved in full. This is transparent — no action needed on your side.
# Troubleshooting
Source: https://docs.inwealth.fr/guides/troubleshooting
Solutions to common integration issues
# Troubleshooting
## Authentication issues
**Cause:** The `Authorization` header is missing or malformed.
**Fix:** Ensure your request includes the header in the correct format:
```
Authorization: Bearer sk_live_your_key_here
```
Common mistakes:
* Missing the `Bearer ` prefix (with space)
* Extra whitespace or newline in the key
* Sending the key as a query parameter instead of a header
**Cause:** The API key does not match any active key in our system.
**Fix:**
* Verify you are using the correct key (starts with `sk_live_`)
* Check that the key has not been revoked — contact your account manager
* If you lost your key, request a new one (keys are shown only once at generation)
## Request issues
**Cause:** A required field is missing from the request body.
**Fix:** Ensure your JSON body includes both required fields:
```json theme={null}
{
"messages": [{"role": "user", "content": "Your question"}],
"session_id": "your-session-id"
}
```
**Cause:** The `effort` parameter has an unsupported value.
**Fix:** Use one of: `"low"`, `"medium"`, `"high"`, `"max"`, or omit the field entirely (defaults to auto).
**Possible causes:**
* Your SSE parser is not handling multi-line chunks correctly
* The connection was closed prematurely (timeout)
**Fix:**
* Buffer incoming chunks and split on `\n\n` (double newline) to separate SSE events
* Increase your HTTP client timeout — complex queries with `extended_thinking` can take 30-60 seconds
* Listen for the `done` event to confirm the stream completed
## Rate limiting
**Cause:** Your organization has consumed its daily token allowance.
**Fix:**
* Wait until midnight UTC for the quota to reset
* The error message includes the exact reset time
* Contact your account manager to increase your daily limit
**Prevention:**
* Use `effort: "low"` for simple questions
* Reuse `session_id` across turns to activate prompt caching
* Trim conversation history for long sessions
* Only enable `extended_thinking` when needed
## Performance
**Cause:** The API container was idle and is booting up.
**How to detect:** Call `GET /health` — if the response takes more than 2 seconds, the container is warming up.
**Fix:**
* The first request after an idle period may take a few extra seconds — this is normal
* Subsequent requests will be fast
* If you need consistent low latency, schedule periodic health checks to keep the container warm
**Cause:** `extended_thinking: true` adds a reasoning phase before the answer, which takes longer.
**Fix:**
* Only use `extended_thinking` for complex or cross-border questions
* For simple factual queries, leave it disabled (default `false`)
* Combine with `effort: "low"` or `"medium"` to limit analysis depth
## Still stuck?
Contact your iNwealth account manager or reach out to our technical team for assistance.
# Introduction
Source: https://docs.inwealth.fr/introduction
Integrate AI-powered wealth intelligence into your product
# iNwealth B2B API
The iNwealth API gives enterprise clients direct access to our AI-powered wealth intelligence agent. Embed expert knowledge into your own application — white-label, real-time, multilingual.
## What you get
`POST /api/agent` — streaming SSE response with sourced expert answers
`sk_live_xxxx...` — SHA-256 hashed, shown once at generation
France, Switzerland, Italy, Belgium, Luxembourg, Germany, Spain, Portugal, UK, Monaco, Greece, Andorra, Netherlands, USA, Mauritius, Morocco, International
French, English, German, Spanish, Italian, Portuguese
## Base URL
```
https://api.inwealth.fr
```
## Quick start
```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": "Tax advantages of PER in France?"}],
"session_id": "session-001"
}'
```
The response is a **streaming SSE** (Server-Sent Events) flow with real-time text fragments.