Skip to content

.Net: New Feature: .Net - OpenRouter Connector #10530

Closed
@tntwist

Description

@tntwist

name: OpenRouter connector
about: Add a connector to open router


Hi there,
it would be nice to have a connector for OpenRouter.
OpenRouter makes it really easy to use multiple ai providers with a single unified api.
From their docs their should be compatible with the OpenAI SDK (see here: https://openrouter.ai/docs/quickstart)

I also played around using the exiting Connector for OpenAi and changed the Endpoint to "https://openrouter.ai/api/v1" like this:

  kernelBuilder.AddOpenAIChatCompletion(
      modelId: model.ProviderIdentifier,
      apiKey: settings.OpenRouterSettings.ApiKey!,
      endpoint: new("https://openrouter.ai/api/v1")
  );

Chat completion does work with this when the response of OpenRouter is successfull.
If there is an error providerwise that is not perfectly handled since open router returns a 200 status code with some error message like this:

{
    "error": {
        "message": "Provider returned error",
        "code": 400,
        "metadata": {
            "raw": "{\n  \"error\": {\n    \"code\": 400,\n    \"message\": \"Invalid JSON payload received. Unknown name \\\"additionalProperties\\\" at 'generation_config.response_schema.properties[0].value.items': Cannot find field.\",\n    \"status\": \"INVALID_ARGUMENT\",\n    \"details\": [\n      {\n        \"@type\": \"type.googleapis.com/google.rpc.BadRequest\",\n        \"fieldViolations\": [\n          {\n            \"field\": \"generation_config.response_schema.properties[0].value.items\",\n            \"description\": \"Invalid JSON payload received. Unknown name \\\"additionalProperties\\\" at 'generation_config.response_schema.properties[0].value.items': Cannot find field.\"\n          }\n        ]\n      }\n    ]\n  }\n}\n",
            "provider_name": "Google AI Studio"
        }
    },
    "user_id": "*******"
}

Using the OpenAi connector we get a null pointer exception since there is no real response.

So best would be to have a real OpenRouter connector that handles this correctly rather than using the OpenAI connector.

Metadata

Metadata

Labels

.NETIssue or Pull requests regarding .NET codestaleIssue is stale because it has been open for a while and has no activity

Projects

Status

Sprint: Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions