danny-avila / LibreChat

Enhanced ChatGPT Clone: Features Anthropic, AWS, OpenAI, Assistants API, Azure, Groq, o1, GPT-4o, Mistral, OpenRouter, Vertex AI, Gemini, Artifacts, AI model switching, message search, langchain, DALL-E-3, ChatGPT Plugins, OpenAI Functions, Secure Multi-User System, Presets, completely open-source for self-hosting. Actively in public development.
https://librechat.ai/
MIT License
17.57k stars 2.91k forks source link

Negative Token Cost Leading to Huge Balance Increase [Bug]: #2359

Closed DanBtt closed 5 months ago

DanBtt commented 5 months ago

What happened?

I was testing out user balances when I noticed one user balance of had unexpectedly increased from around 500000 to 83482456.5 check the debug logs on the api container showed that it was when I was using the openrouter/auto model. Looks like it is using a token cost of -1000000 per token.

Below are the relevent logs for another prompt I tried for openrouter/auto that got me up to a balance of 485482456.5

Steps to Reproduce

  1. Enable openrouter 'openrouter/auto' model in librechat.yaml - I actually did this via fetch: true plus having it in the default list
  2. Login with a user account and chat to the openrouter/auto model
  3. Balance will be increased
  4. Profit

What browsers are you seeing the problem on?

Safari

Relevant log output

2024-04-09T02:52:51.884Z debug: [BaseClient] userMessage
{
  messageId: "fcc0eb01-e578-4966-a629-82cee7ac7afd",
  parentMessageId: "00000000-0000-0000-0000-000000000000",
  conversationId: "57733b85-9469-4c47-a736-97ed572c02ba",
  sender: "User",
  text: "Can you tell me a story?",
  isCreatedByUser: true,
  tokenCount: 11,
}
2024-04-09T02:52:51.919Z debug: [Balance.check]
{
  user: "6614825b436115686e85e5b7",
  model: "openrouter/auto",
  endpoint: "OpenRouter",
  valueKey: undefined,
  tokenType: "prompt",
  amount: 14,
  balance: 83482456.5,
  multiplier: -1000000,
  endpointTokenConfig: true,
}
2024-04-09T02:52:51.919Z debug: [Balance.check]
{
  tokenCost: -14000000,
}
2024-04-09T02:52:51.919Z debug: [OpenAIClient] chatCompletion
{
  baseURL: "https://openrouter.ai/api/v1",
    modelOptions.model: "openrouter/auto",
    modelOptions.temperature: 1,
    modelOptions.top_p: 1,
    modelOptions.presence_penalty: 0,
    modelOptions.frequency_penalty: 0,
    // 3 stop(s)
    modelOptions.stop: ["||>","\nUser:","<|diff_marker|>"],
    modelOptions.user: "6614825b436115686e85e5b7",
    modelOptions.stream: true,
    // 1 message(s)
    modelOptions.messages: [{"role":"user","content":"Can you tell me a story?"}],
}
2024-04-09T02:53:12.018Z debug: [OpenAIClient] chatCompletion response
{
  object: "chat.completion",
  id: "gen-JRIZMZMa36Co2jgQ7oariLzzFwhO",
  // 1 choice(s)
  choices: [{"message":{"role":"assistant","content":"Once upon a time, in a land far, far away, there was a mag... [truncated]],
  created: 1712631191,
  model: "mistralai/mistral-medium",
}
2024-04-09T02:53:12.021Z debug: [spendTokens] conversationId: 57733b85-9469-4c47-a736-97ed572c02ba | Context: message | Token usage:
{
  promptTokens: 14,
  completionTokens: 388,
}
2024-04-09T02:53:12.030Z debug: [spendTokens] Transaction data record against balance:
{
  user: "6614825b436115686e85e5b7",
  prompt: 14000000,
  promptRate: -1000000,
  completion: 388000000,
  completionRate: -1000000,
  balance: 485482456.5,
}

Screenshots

No response

Code of Conduct

danny-avila commented 5 months ago

Already taken care of by this PR: https://github.com/danny-avila/LibreChat/pull/2350

Please update to the latest commit.