Skip to content

feat: per-request headers on generate calls - #40

Merged
arnaub merged 1 commit into
mainfrom
feat/per-request-headers
Jul 27, 2026
Merged

feat: per-request headers on generate calls#40
arnaub merged 1 commit into
mainfrom
feat/per-request-headers

Conversation

@arnaub

@arnaub arnaub commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Why

Factorial is moving backend↔factorial-agent auth from the shared MASTRA_API_KEY secret to factorial-id service tokens with actor attribution (FCT-58575). The caller needs to set per-request headers — an Authorization service token plus X-Factorial-Actor-Type/X-Factorial-Actor-Id — which the client can't do today: it only sends the process-wide Ai.config.api_key.

What

  • Ai::Agent#generate_text / #generate_object accept an optional headers: hash (default {}).
  • Ai::Client#generate (abstract), Ai::Clients::Mastra#generate and #response thread it through; per-request headers are applied after the global Origin/Authorization, so they win on conflict.
  • Ai::Clients::Test accepts the kwarg and exposes last_headers for assertions.
  • Version bumped to 0.7.0.

Consumer

factorialco/factorial#105401's AiInteractions::AgentGateway is the first caller — its pending end-to-end specs assert this exact header contract and flip green when the monorepo's Gemfile picks this up.

🤖 Generated with Claude Code

Ai::Agent#generate_text/#generate_object accept a headers: hash that the
Mastra client sends on the HTTP request, overriding the global config
(e.g. a service-to-service Authorization token and actor headers instead
of the shared MASTRA_API_KEY). Test client records last_headers.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@arnaub
arnaub marked this pull request as ready for review July 23, 2026 09:50
@arnaub
arnaub requested a review from a team as a code owner July 23, 2026 09:50
@arnaub
arnaub merged commit 69cbdc2 into main Jul 27, 2026
1 check passed
@arnaub
arnaub deleted the feat/per-request-headers branch July 27, 2026 14:57
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.

2 participants