Skip to content

Add the possibility to add extra header fields in the RunConfig or Agents #549

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
jonnyk20 opened this issue Apr 19, 2025 · 3 comments
Open
Labels
enhancement New feature or request

Comments

@jonnyk20
Copy link

jonnyk20 commented Apr 19, 2025

I appreciate that you recently enabled the extra_body option in the RunConfig based on #487

Would it be possible to have the extra_headers option as well? The analytics provider I use uses the headers to track requests, so without it I'm unable to do monitoring at a per-user level. I can only set the default headers on the client, which will be the same for all requests.

Here an example how to do it in the openai package:

import openai
client = openai.OpenAI()

response = client.chat.completions.create(model="gpt-4o", messages = [
    {
        "role": "user",
        "content": "Write a short poem about GitHub"
    }
], 
# it is possible to send additional header fields with "extra_headers"
    extra_headers={
      "field1": "value 1"
    }
) 

Unfortunately I wasn't able to find a way to mimic this behaviour.

I would suggest to add the feature to provide extra header fields in the RunConfig:
result = Runner.run_sync(agent, input="Say this is a test", run_config=RunConfig(extra_headers={"field1":"value 1"}))

Maybe it would also benefit if you can set extra header fields on a per agent basis.
agent = Agent(name="Assistant", instructions="You are a helpful assistant", extra_headers={"field1":"value 1"})
These will then be added on top of the extra fields which have been set in the RunConfig.

@jonnyk20
Copy link
Author

I've written a PR for it here but it doesn't look like I have the ability to request reviews: #550

Is there a process we should follow to submit PRs?

@DanieleMorotti
Copy link
Contributor

Hi, I don't think your code is correct. You pass extra_headers twice, ignoring the already passed HEADERS.

You should change to something like:

...
    extra_query=model_settings.extra_query,
    extra_body=model_settings.extra_body,
    extra_headers={**HEADERS, **model_settings.extra_headers},
    metadata=self._non_null_or_not_given(model_settings.metadata)
)

if both are dictionaries, I didn't check that.

@jonnyk20
Copy link
Author

Hi, I don't think your code is correct. You pass extra_headers twice, ignoring the already passed HEADERS.

You should change to something like:

...
extra_query=model_settings.extra_query,
extra_body=model_settings.extra_body,
extra_headers={**HEADERS, **model_settings.extra_headers},
metadata=self._non_null_or_not_given(model_settings.metadata)
)
if both are dictionaries, I didn't check that.

@DanieleMorotti My mistake, I've just updated the PR now, thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants