POST /v1/agents/{agent_id}/chat and POST /v1/agents/{agent_id}/chat/stream, require an Idempotency-Key header. A request without one is 422 validation_error.
Choosing a key
Any value of 1-255 characters that is unique per logical request. A UUID generated at the moment you decide to send a message is the simplest choice. Keys are scoped to your API key, so you do not need to worry about collisions with other keys.What a retry returns
Retrying with the sameIdempotency-Key and the same body returns the stored result: the original request_id, the same assistant message and the same usage. No second reply is generated and nothing is charged again.
Records live for 24 hours. After that the same key starts a fresh request.
The stored result is what the runtime persisted anyway: the assistant message tagged with the request id and the LLM usage billed under that id. A replay therefore never calls the model or touches the balance, even if the first attempt died halfway through.
Conflicts
Streaming and disconnects
The rules are the same on the streaming endpoint. If your client disconnects mid-stream, the reply keeps being produced and stored. A retry with the same key streamsresponse.created followed directly by response.completed carrying the stored result, without replaying the deltas. See Streaming.