fix(llm): send temperature through extra_body on anthropic>=1.0 by abouchard11 · Pull Request #2001 · getzep/graphiti · GitHub
Skip to content

fix(llm): send temperature through extra_body on anthropic>=1.0 - #2001

Open
abouchard11 wants to merge 1 commit into
getzep:mainfrom
abouchard11:fix/anthropic-sdk-1x-sampling
Open

abouchard11 wants to merge 1 commit into
getzep:mainfrom
abouchard11:fix/anthropic-sdk-1x-sampling

Conversation

@abouchard11

Copy link
Copy Markdown

Summary

With anthropic 1.0.0 or later installed, AnthropicClient fails on every call:

TypeError: AsyncMessages.create() got an unexpected keyword argument 'temperature'

The 1.x SDK removed the temperature keyword from messages.create(), and _generate_response always passes it. pyproject.toml allows 1.x (anthropic>=0.49.0) while uv.lock pins 0.111.0, so CI does not see the failure but a fresh pip install "graphiti-core[anthropic]" does.

The API still accepts the field, and the SDK's v1 migration guide gives extra_body as the way to send it. This change checks whether the installed SDK's messages.create has a temperature keyword:

  • If it does (0.x), the call is unchanged.
  • If it does not (1.x), the value goes through extra_body.

The request body is the same in both cases, so LLMConfig.temperature keeps working on either SDK line.

Not changed here: temperature=None (#1794, #1797) and which models accept sampling parameters. Both behave the same before and after this change.

Type of change

  • Bug fix
  • Feature (linked Feature issue already has rfc-approved)
  • Documentation
  • Maintenance or refactor

Related issue

Fixes #2000

Design approval

  • This is not a feature pull request.
  • The linked Feature issue has the rfc-approved label after discussion with the Graphiti team.

Testing

  • Tests were added or updated for behavior changes.
  • make check passes.
  • Tests are not applicable; the reason is explained below.

make format and make lint pass. I did not run make test in full because it needs a local Neo4j; I ran the unit-test selection from .github/workflows/unit_tests.yml instead.

Three tests added to tests/llm_client/test_anthropic_client.py:

  • An SDK without the temperature keyword receives the value through extra_body.
  • An SDK with the keyword is called exactly as before.
  • The request binds to the real signature of whichever anthropic version is installed. On main with anthropic 1.13.0 this test fails with the TypeError above.

Results:

Check anthropic 0.111.0 (uv.lock) anthropic 1.13.0
tests/llm_client/test_anthropic_client.py 14 passed 14 passed
Unit-test selection from unit_tests.yml 708 passed, 12 skipped 708 passed, 12 skipped
pyright ./graphiti_core 0 errors 0 errors

The client tests also pass on anthropic 0.49.0 (the declared floor), 0.125.0 and 1.0.0.

I captured the HTTP request body with a local stub server. It is identical for main on 0.111.0, this branch on 0.111.0, and this branch on 1.13.0, with temperature present in all three.

Breaking changes

  • This change affects an existing public API, data model, or deployment.

Checklist

  • I opened or linked an existing issue before this pull request.
  • I reviewed my own changes.
  • I updated documentation for changed behavior or public interfaces.
  • I did not commit secrets, credentials, customer data, or other sensitive information.
  • I will complete the Contributor License Agreement when prompted.

No documentation change: no public interface or documented behavior changes.

anthropic 1.0.0 removed the temperature keyword from messages.create, so
AnthropicClient raised "TypeError: AsyncMessages.create() got an unexpected
keyword argument 'temperature'" on every call once a 1.x SDK was installed.
pyproject allows it (anthropic>=0.49.0); uv.lock pins 0.111.0, so CI does not
see it.

The API still takes the field. When the installed SDK has no temperature
keyword, pass it through extra_body, which the SDK merges into the request
JSON. Older SDKs keep the keyword. The request body is the same in both cases.
@chatgpt-codex-connector

Copy link
Copy Markdown

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] AnthropicClient raises TypeError on every call with anthropic>=1.0

1 participant