Skip to content

API Key Specification for Different Agents #201

Closed

Description

@BowenBryanWang

Please read this first

  • Have you read the docs?Agents SDK docs
  • Have you searched for related issues? Others may have had similar requesrs

Describe the feature

What is the feature you're requesting? How would it work? Please provide examples and details if possible.

Hi developer,

I'm curious about how do I specify different OpenAI_API_KEYs to different agent class? The issue is that I have specific key for computer-use-preview agent class, which I wish to separate against the key used for WebSearchTool agent class.

Thank you for your help!

Activity

  1. de-code commented on Mar 18, 2025

    @de-code

    I believe you could just pass a model instance to the agent.

    import os
    from openai import AsyncOpenAI
    from agents import Agent, OpenAIChatCompletionsModel
    
    
    model = OpenAIChatCompletionsModel(
        model=os.getenv('OPENAI_MODEL_ID', 'gpt-4o-mini'),
        openai_client=AsyncOpenAI(
            base_url=os.getenv('OPENAI_BASE_URL', 'https://api.openai.com/v1'),
            api_key=os.environ['OPENAI_API_KEY']
        )
    )
    
    agent = Agent(
        name='Assistant',
        instructions='You are a helpful assistant',
        model=model
    )
  2. rm-openai commented on Mar 18, 2025

    @rm-openai
    Collaborator

    Yup thats right ^

  3. BowenBryanWang commented on Mar 20, 2025

    @BowenBryanWang
    Author

    Yes but remember to make sure that different keys must belong to the same organization, otherwise the data retention might not work, items stored in previous conversation might not be found by following agents...

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions