Created
          October 25, 2024 15:13 
        
      - 
      
- 
        Save vrushankportkey/68ae603d23fd33366c852875043e3e82 to your computer and use it in GitHub Desktop. 
    Calling the Portkey API in C#
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | // dotnet add package RestSharp | |
| using RestSharp; | |
| using System; | |
| using System.Threading.Tasks; | |
| public class Program | |
| { | |
| private static readonly string PortkeyApiKey = Environment.GetEnvironmentVariable("PORTKEY_API_KEY"); | |
| private static readonly string OpenAiVirtualKey = "YOUR_OPENAI_VIRTUAL_KEY"; | |
| public static async Task Main() | |
| { | |
| var client = new RestClient("https://api.portkey.ai/v1/chat/completions"); | |
| var request = new RestRequest(); | |
| request.AddHeader("x-portkey-api-key", PortkeyApiKey); | |
| request.AddHeader("x-portkey-virtual-key", OpenAiVirtualKey); | |
| request.AddJsonBody(new | |
| { | |
| model = "gpt-4o-mini", | |
| max_tokens = 100, | |
| messages = new[] { new { role = "user", content = "1729" } } | |
| }); | |
| var response = await client.ExecutePostAsync<dynamic>(request); | |
| Console.WriteLine(response.Content); | |
| } | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment