Skip to content

[Bug]: Session logs are not showing pricing when completions.create from Anthropic is used.Β #678

@Dwij1704

Description

@Dwij1704

Contact Details

No response

πŸ“¦ Package Version

0.3.26

🎞️ Framework Version

No response

πŸ”Ž Describe the Bug

Was testing completions.create from Anthropic, and it seems like it's not tracking cost.
Reference script:

import agentops
from anthropic import Anthropic

agentops.init(
    api_key='<AGENTOPS_KEY>',
    default_tags=['anthropic']
)


client = Anthropic(api_key='<ANTHROPIC_KEY>')


models = ["claude-2"]


def get_ai_response(model_name):
    response = client.completions.create(
        model=model_name,
        prompt="\n\nHuman: Write a haiku about AI and humans working together\n\nAssistant:",
        max_tokens_to_sample=100
    )
    return response.completion


for model in models:
    print(f"Response from {model}:")
    try:
        ai_response = get_ai_response(model)
        print(ai_response)
    except Exception as e:
        print(f"Error with model {model}: {e}")
    print("-" * 50)


agentops.end_session('Success')

🀝 Contribution

  • Yes, I'd be happy to submit a pull request with these changes.
  • I need some guidance on how to contribute.
  • I'd prefer the AgentOps team to handle this update.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions