web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Copilot Studio / How to Integrate Copil...
Copilot Studio
Answered

How to Integrate Copilot Studio Agent with a Website Using API?

(1) ShareShare
ReportReport
Posted on by 101

Hello Team,

I have created a Copilot Agent using Copilot Studio and published it on our public website using an iframe. Currently, the agent does not have any authentication configured because we want it to be publicly accessible.

However, our website development team has raised a security concern with this approach, as embedding the Copilot Agent directly using an iframe may not be the most secure or recommended approach.

We are looking for an alternative integration approach. For example:

  • Is it possible to expose the Copilot Studio Agent through an API or another secure endpoint?
  • Can our website development team call the agent through an API, receive the response, and build their own custom UI instead of embedding the agent using an iframe?
  • Is there any recommended architecture or Microsoft-supported approach for securely integrating a Copilot Studio Agent with a public-facing website?

If anyone has implemented a similar solution or has any recommendations, I would appreciate your suggestions.

  • Verified answer
    Haque Profile Picture
    4,280 Super User 2026 Season 2 on at
    HI @Patel Asutosh 27,
     
    I assume the debate with security team is how they want to be public, is it open for anybody or it should be open for only your organisation? 
     
    • Microsoft 365 Agents SDK.  Copilot Studio agents can be integrated into your website or native apps using this SDK.
    • Direct Line API (When SDK is Not Suitable):  Test conversational agents using Direct Line API. For security, we can check here.
    • Authentication and Security for secure, authenticated access, configure your agent to use Microsoft Authentication (Entra ID).
     
     
     

    I am sure some clues I tried to give. If these clues help to resolve the issue brought you by here, please don't forget to check the box Does this answer your question? At the same time, I am pretty sure you have liked the response!
  • Suggested answer
    11manish Profile Picture
    4,802 Super User 2026 Season 2 on at
    Keep the agent unauthenticated if it genuinely needs to be public, but replace the iframe only if you need a custom UI. Use Direct Line with a server-side token-generation layer, and never expose the Web Channel/Direct Line secret in client-side JavaScript.
  • Patel Asutosh 27 Profile Picture
    101 on at
    @Haque 

    The agent is intentionally open to everyone because its knowledge source comes from our public website, so there is no sensitive or authenticated data involved.

    What our development team is looking for is a way to integrate the agent into our existing website UI without using the standard iframe/embed approach.

    For example, the user enters a question in our custom website UI, the question is sent to the Copilot Studio agent through an API, and the agent's response is returned to our application so that the development team can display it in their own UI.

    I have looked into the Microsoft 365 Agents SDK and Direct Line API, but I'm still not completely clear on the implementation and which approach would be best for this scenario.

    Do you have any detailed documentation, sample projects, or videos that demonstrate this type of integration step-by-step?

    I found Microsoft's documentation on using Direct Line API for custom applications, as well as the Copilot Studio samples, but a practical video or end-to-end example would be very helpful.

  • Suggested answer
    Haque Profile Picture
    4,280 Super User 2026 Season 2 on at
    HI @Patel Asutosh 27,
     
    I believe this  video will help you to kick start.
     
  • Patel Asutosh 27 Profile Picture
    101 on at
    @11manish , is there any videos or blog have that explain the entire process? 

    If have please share.
  • Verified answer
    Valantis Profile Picture
    7,545 Super User 2026 Season 2 on at
     
    Microsoft's own Copilot Studio Samples repo has a working end to end example for exactly this, DirectLine JS sample under UI Samples, plain HTML/JS hitting the DirectLine API directly, no WebChat, no iframe. https://microsoft.github.io/CopilotStudioSamples/ui/custom-ui/directline-js/

    Also worth running through, a decision guide from the Copilot Studio CAT team, basically a short wizard that asks about your setup and points you to the matching code sample. Covers your exact scenario, custom UI without WebChat. https://microsoft.github.io/mcscatblog/posts/copilot-studio-api-decision-guide/
     
      Best regards,

    Valantis   ✅ If this helped solve your issue, please Accept as Solution so others can find it quickly.

    ❤️ If it didn’t fully solve it but was still useful, please click “Yes” on “Was this reply helpful?” or leave a Like :).

    🏷️ For follow-ups  @Valantis.

    📝 https://valantisond365.com/
    💼 LinkedIn   ▶️ YouTube
  • Suggested answer
    M Bilal Khan Profile Picture
    376 on at

    Yes, there is a supported alternative to the iframe approach.

    The key distinction is that you don't normally expose the Copilot Studio agent as a generic REST API and then simply POST questions to it. For a custom website UI, Microsoft supports connecting the website to the agent through Direct Line.

    Microsoft's current documentation explicitly lists Direct Line as the option for custom applications/web clients, and Direct Line provides REST/WebSocket communication with the Copilot Studio agent.

    Recommended architecture

    Instead of:

    Website
       ↓
    iframe
       ↓
    Copilot Studio Web Chat
    

    you can build:

    Custom Website UI
           ↓
    Your backend / secure token endpoint
           ↓
    Direct Line token
           ↓
    Copilot Studio Agent
           ↓
    Response
           ↓
    Your custom UI
    

    The website development team can therefore build their own chat interface rather than displaying the Microsoft-provided iframe UI.

    Microsoft also provides a Copilot Studio client/Web Chat integration specifically for custom web applications.

    One important security point

    I would not put the Direct Line secret in the browser.

    If you enable Direct Line channel security, the recommended pattern is to keep the secret on your server and generate a short-lived Direct Line token for the browser. Microsoft documents this secured Direct Line approach specifically for controlling access to the web channel.

    So, for example:

    Browser
       │
       │ GET /api/copilot/token
       ▼
    Website Backend
       │
       │ Direct Line secret
       ▼
    Microsoft Direct Line
       │
       ▼
    Copilot Studio Agent
    

    The browser receives a token, not your permanent Direct Line secret.

    What about authentication?

    If the agent is genuinely intended to be public and unauthenticated, No authentication is supported. Microsoft notes that this means anyone who has access to the agent/link can interact with it, so you should only expose public information/actions through that agent.

    If the agent needs to access user-specific/private data, I would not leave it unauthenticated just to make the website integration easier. In that case, use an appropriate authentication architecture and pass the authenticated user context through the supported authentication/Direct Line pattern.

    So I would choose based on the requirement

    Simple public chatbot:

    Copilot Studio
       ↓
    No authentication
       ↓
    Web channel / iframe
    

    This is actually a supported Microsoft scenario.

    Public website + completely custom UI:

    Custom website
       ↓
    Backend token endpoint
       ↓
    Direct Line
       ↓
    Copilot Studio
    

    This is the approach I would recommend if the website team wants full control over the UI/UX.

    Authenticated website + user-specific data:

    User
     ↓
    Website authentication
     ↓
    Secure backend / token flow
     ↓
    Direct Line + Copilot authentication
     ↓
    Copilot Studio
     ↓
    User-authorized data
    

    That last scenario needs more careful Entra/OAuth configuration; I wouldn't simply expose a REST endpoint containing the agent credentials.

    One other point: "Create REST API actions for custom agents" is not the same thing as exposing the entire Copilot Studio conversation as a generic REST API. If the requirement is a conversational custom UI, Direct Line is the more relevant integration mechanism.

    So the website team's concern about iframe doesn't necessarily mean the current implementation is insecure. The iframe itself is a Microsoft-supported web deployment option. The real security question is what the agent can access and how the channel is secured. If they need a custom frontend, I'd move to Direct Line + a server-side token endpoint, rather than trying to turn the agent into a generic REST API.

  • Suggested answer
    Mohsin Ali Profile Picture
    1,075 on at
    Hello @Patel Asutosh 27 - There are couple of options you might want to explore and proceed with more secured approach. 
     
    Adding a quick walkthrough for adding copilot studio in custom apps using agent sdk and direct line
     

     
  • Valantis Profile Picture
    7,545 Super User 2026 Season 2 on at

    Hi @Patel Asutosh 27,

    Just wanted to check in and see if everything is working now. If you still need any help, feel free to let me know.

    Also, if the issue is resolved, it would be great if you could mark the answer as solved so others with the same question can find it easily.

     

    Thanks and have a great day!

     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Copilot Studio

#1
Mohsin Ali Profile Picture

Mohsin Ali 360

#2
Valantis Profile Picture

Valantis 253 Super User 2026 Season 2

#3
11manish Profile Picture

11manish 184 Super User 2026 Season 2

Last 30 days Overall leaderboard