Skip to content

fix(api): return 413 content_too_long instead of 500 when embedder co…#18

Merged
yhyyz merged 2 commits into
ourmem:mainfrom
doctatortot:fix/content-too-long-413
May 21, 2026
Merged

fix(api): return 413 content_too_long instead of 500 when embedder co…#18
yhyyz merged 2 commits into
ourmem:mainfrom
doctatortot:fix/content-too-long-413

Conversation

@doctatortot
Copy link
Copy Markdown
Contributor

…ntext exceeded

Closes #15.

Embedding content longer than the configured embedder's context window is a client-input problem, but it surfaced as 500 internal_error with the real cause buried inside a stringified upstream embedder error (callers had to substring-match "exceeds the context window").

Add OmemError::ContentTooLong { length, hint }, map it to 413 Payload Too Large in the IntoResponse impl, and recognize the over-context signature at the content embed call sites (create + update). Response now:

{"error":{"code":"content_too_long",
"message":"content too long: 7410 chars exceed the embedder's context window",
"hint":"split the content into smaller memories or configure a longer-context embedder"}}

Other embed failures still map to Embedding/500. This is Option A from the issue; pre-flight token estimate (Option B) left as a possible follow-up.

doctatortot and others added 2 commits May 20, 2026 06:08
…ntext exceeded

Closes ourmem#15.

Embedding content longer than the configured embedder's context window is a
client-input problem, but it surfaced as 500 internal_error with the real
cause buried inside a stringified upstream embedder error (callers had to
substring-match "exceeds the context window").

Add OmemError::ContentTooLong { length, hint }, map it to 413 Payload Too
Large in the IntoResponse impl, and recognize the over-context signature at
the content embed call sites (create + update). Response now:

  {"error":{"code":"content_too_long",
            "message":"content too long: 7410 chars exceed the embedder's context window",
            "hint":"split the content into smaller memories or configure a longer-context embedder"}}

Other embed failures still map to Embedding/500. This is Option A from the
issue; pre-flight token estimate (Option B) left as a possible follow-up.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@yhyyz yhyyz merged commit be36b1f into ourmem:main May 21, 2026
1 check passed
@yhyyz
Copy link
Copy Markdown
Contributor

yhyyz commented May 21, 2026

Merged and deployed! Clean implementation of Option A. The map_embed_error helper with keyword matching is pragmatic and correct. Closes #15. 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Long memory content returns 500 instead of a structured 413/422 when embedder context is exceeded

2 participants