Skip to content

Instantly share code, notes, and snippets.

@vrushankportkey
Created October 25, 2024 15:13
Show Gist options
  • Save vrushankportkey/68ae603d23fd33366c852875043e3e82 to your computer and use it in GitHub Desktop.
Save vrushankportkey/68ae603d23fd33366c852875043e3e82 to your computer and use it in GitHub Desktop.
Calling the Portkey API in C#
// 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