{"id":26050876,"url":"https://github.com/simonw/llm-anthropic","last_synced_at":"2026-03-04T18:03:57.836Z","repository":{"id":268609316,"uuid":"904932452","full_name":"simonw/llm-anthropic","owner":"simonw","description":"LLM access to models by Anthropic, including the Claude series","archived":false,"fork":false,"pushed_at":"2026-02-17T23:55:50.000Z","size":185,"stargazers_count":191,"open_issues_count":22,"forks_count":23,"subscribers_count":8,"default_branch":"main","last_synced_at":"2026-02-18T04:53:09.938Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/simonw.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null},"funding":{"github":"simonw"}},"created_at":"2024-12-17T20:36:48.000Z","updated_at":"2026-02-18T03:46:26.000Z","dependencies_parsed_at":"2024-12-17T20:47:34.015Z","dependency_job_id":"868944e4-7d6c-42eb-ab8c-9a2f3e6202a7","html_url":"https://github.com/simonw/llm-anthropic","commit_stats":null,"previous_names":["simonw/llm-anthropic"],"tags_count":21,"template":false,"template_full_name":null,"purl":"pkg:github/simonw/llm-anthropic","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simonw%2Fllm-anthropic","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simonw%2Fllm-anthropic/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simonw%2Fllm-anthropic/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simonw%2Fllm-anthropic/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/simonw","download_url":"https://codeload.github.com/simonw/llm-anthropic/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simonw%2Fllm-anthropic/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30088344,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-04T15:40:14.053Z","status":"ssl_error","status_checked_at":"2026-03-04T15:40:13.655Z","response_time":59,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-03-08T03:01:21.975Z","updated_at":"2026-03-04T18:03:57.828Z","avatar_url":"https://github.com/simonw.png","language":"Python","funding_links":["https://github.com/sponsors/simonw"],"categories":["Python"],"sub_categories":[],"readme":"# llm-anthropic\n\n[![PyPI](https://img.shields.io/pypi/v/llm-anthropic.svg)](https://pypi.org/project/llm-anthropic/)\n[![Changelog](https://img.shields.io/github/v/release/simonw/llm-anthropic?include_prereleases\u0026label=changelog)](https://github.com/simonw/llm-anthropic/releases)\n[![Tests](https://github.com/simonw/llm-anthropic/actions/workflows/test.yml/badge.svg)](https://github.com/simonw/llm-anthropic/actions/workflows/test.yml)\n[![License](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](https://github.com/simonw/llm-anthropic/blob/main/LICENSE)\n\nLLM access to models by Anthropic, including the Claude series\n\n## Installation\n\nInstall this plugin in the same environment as [LLM](https://llm.datasette.io/).\n```bash\nllm install llm-anthropic\n```\n\n\u003cdetails\u003e\u003csummary\u003eInstructions for users who need to upgrade from \u003ccode\u003ellm-claude-3\u003c/code\u003e\u003c/summary\u003e\n\n\u003cbr\u003e\n\nIf you previously used `llm-claude-3` you can upgrade like this:\n\n```bash\nllm install -U llm-claude-3\nllm keys set anthropic --value \"$(llm keys get claude)\"\n```\nThe first line will remove the previous `llm-claude-3` version and install this one, because the latest `llm-claude-3` depends on `llm-anthropic`.\n\nThe second line sets the `anthropic` key to whatever value you previously used for the `claude` key.\n\n\u003c/details\u003e\n\n## Usage\n\nFirst, set [an API key](https://console.anthropic.com/settings/keys) for Anthropic:\n```bash\nllm keys set anthropic\n# Paste key here\n```\n\nYou can also set the key in the environment variable `ANTHROPIC_API_KEY`\n\nRun `llm models` to list the models, and `llm models --options` to include a list of their options.\n\nRun prompts like this:\n```bash\nllm -m claude-opus-4.5 'Fun facts about walruses'\nllm -m claude-sonnet-4.5 'Fun facts about pelicans'\nllm -m claude-3.5-haiku 'Fun facts about armadillos'\nllm -m claude-haiku-4.5 'Fun facts about cormorants'\n```\nImage attachments are supported too:\n```bash\nllm -m claude-sonnet-4.5 'describe this image' -a https://static.simonwillison.net/static/2024/pelicans.jpg\nllm -m claude-haiku-4.5 'extract text' -a page.png\n```\nThe Claude 3.5 and 4 models can handle PDF files:\n```bash\nllm -m claude-sonnet-4.5 'extract text' -a page.pdf\n```\nAnthropic's models support [schemas](https://llm.datasette.io/en/stable/schemas.html). Here's how to use Claude 4 Sonnet to invent a dog:\n\n```bash\nllm -m claude-sonnet-4.5 --schema 'name,age int,bio: one sentence' 'invent a surprising dog'\n```\nExample output:\n```json\n{\n  \"name\": \"Whiskers the Mathematical Mastiff\",\n  \"age\": 7,\n  \"bio\": \"Whiskers is a mastiff who can solve complex calculus problems by barking in binary code and has won three international mathematics competitions against human competitors.\"\n}\n```\n\nNewer models support web search for real-time information:\n```bash\nllm -m claude-3.5-sonnet -o web_search 1 'What is the current weather in San Francisco?'\n```\n\n## Usage from Python\n\nPython code can access the models like this:\n```python\nimport llm\n\nmodel = llm.get_model(\"claude-haiku-4.5\")\nprint(model.prompt(\"Fun facts about chipmunks\"))\n```\nConsult [LLM's Python API documentation](https://llm.datasette.io/en/stable/python-api.html) for more details.\n\nYou can also import the model classes directly, which is useful if you want to point the `base_url` at a different Anthropic-compatible endpoint:\n```python\nfrom llm_anthropic import ClaudeMessages\n\nmodel = ClaudeMessages(\n    \"MiniMax-M2\",\n    base_url=\"https://api.minimax.io/anthropic\"\n)\n\nprint(model.prompt(\"Fun facts about pangolins\", key=\"eyJh...\"))\n```\n\n## Extended reasoning with Claude 3.7 Sonnet and higher\n\nClaude 3.7 introduced [extended thinking](https://www.anthropic.com/news/visible-extended-thinking) mode, where Claude can expend extra effort thinking through the prompt before producing a response.\n\nUse the `-o thinking 1` option to enable this feature:\n\n```bash\nllm -m claude-3.7-sonnet -o thinking 1 'Write a convincing speech to congress about the need to protect the California Brown Pelican'\n```\nThe chain of thought is not currently visible while using LLM, but it is logged to the database and can be viewed using this command:\n```bash\nllm logs -c --json\n```\nOr in combination with `jq`:\n```bash\nllm logs --json -c | jq '.[0].response_json.content[0].thinking' -r\n```\nBy default up to 1024 tokens can be used for thinking. You can increase this budget with the `thinking_budget` option:\n```bash\nllm -m claude-3.7-sonnet -o thinking_budget 32000 'Write a long speech about pelicans in French'\n```\n\n## Model options\n\nThe following options can be passed using `-o name value` on the CLI or as `keyword=value` arguments to the Python `model.prompt()` method:\n\n\u003c!-- [[[cog\nimport cog, llm\n_type_lookup = {\n    \"number\": \"float\",\n    \"integer\": \"int\",\n    \"string\": \"str\",\n    \"object\": \"dict\",\n}\n\nmodel = llm.get_model(\"claude-3.7-sonnet\")\noutput = []\nfor name, field in model.Options.schema()[\"properties\"].items():\n    any_of = field.get(\"anyOf\")\n    if any_of is None:\n        any_of = [{\"type\": field[\"type\"]}]\n    types = \", \".join(\n        [\n            _type_lookup.get(item[\"type\"], item[\"type\"])\n            for item in any_of\n            if item[\"type\"] != \"null\"\n        ]\n    )\n    bits = [\"- **\", name, \"**: `\", types, \"`\\n\"]\n    description = field.get(\"description\", \"\")\n    if description:\n        bits.append('\\n    ' + description + '\\n\\n')\n    output.append(\"\".join(bits))\ncog.out(\"\".join(output))\n]]] --\u003e\n- **max_tokens**: `int`\n\n    The maximum number of tokens to generate before stopping\n\n- **temperature**: `float`\n\n    Amount of randomness injected into the response. Defaults to 1.0. Ranges from 0.0 to 1.0. Use temperature closer to 0.0 for analytical / multiple choice, and closer to 1.0 for creative and generative tasks. Note that even with temperature of 0.0, the results will not be fully deterministic.\n\n- **top_p**: `float`\n\n    Use nucleus sampling. In nucleus sampling, we compute the cumulative distribution over all the options for each subsequent token in decreasing probability order and cut it off once it reaches a particular probability specified by top_p. You should either alter temperature or top_p, but not both. Recommended for advanced use cases only. You usually only need to use temperature.\n\n- **top_k**: `int`\n\n    Only sample from the top K options for each subsequent token. Used to remove 'long tail' low probability responses. Recommended for advanced use cases only. You usually only need to use temperature.\n\n- **user_id**: `str`\n\n    An external identifier for the user who is associated with the request\n\n- **prefill**: `str`\n\n    A prefill to use for the response\n\n- **hide_prefill**: `boolean`\n\n    Do not repeat the prefill value at the start of the response\n\n- **stop_sequences**: `array, str`\n\n    Custom text sequences that will cause the model to stop generating - pass either a list of strings or a single string\n\n- **cache**: `boolean`\n\n    Use Anthropic prompt cache for any attachments or fragments\n\n- **web_search**: `boolean`\n\n    Enable web search capabilities\n\n- **web_search_max_uses**: `int`\n\n    Maximum number of web searches to perform per request\n\n- **web_search_allowed_domains**: `array`\n\n    List of domains to restrict web searches to\n\n- **web_search_blocked_domains**: `array`\n\n    List of domains to exclude from web searches\n\n- **web_search_location**: `dict`\n\n    User location for localizing search results (dict with city, region, country, timezone)\n\n- **thinking**: `boolean`\n\n    Enable thinking mode\n\n- **thinking_budget**: `int`\n\n    Number of tokens to budget for thinking\n\n\u003c!-- [[[end]]] --\u003e\n\nThe `prefill` option can be used to set the first part of the response. To increase the chance of returning JSON, set that to `{`:\n\n```bash\nllm -m claude-sonnet-4.5 'Fun data about pelicans' \\\n  -o prefill '{'\n```\nIf you do not want the prefill token to be echoed in the response, set `hide_prefill` to `true`:\n\n```bash\nllm -m claude-3.5-haiku 'Short python function describing a pelican' \\\n  -o prefill '```python' \\\n  -o hide_prefill true \\\n  -o stop_sequences '```'\n```\nThis example sets `` ``` `` as the stop sequence, so the response will be a Python function without the wrapping Markdown code block.\n\nTo pass a single stop sequence, send a string:\n```bash\nllm -m claude-sonnet-4.5 'Fun facts about pelicans' \\\n  -o stop-sequences \"beak\"\n```\nFor multiple stop sequences, pass a JSON array:\n\n```bash\nllm -m claude-sonnet-4.5 'Fun facts about pelicans' \\\n  -o stop-sequences '[\"beak\", \"feathers\"]'\n```\n\nWhen using the Python API, pass a string or an array of strings:\n\n```python\nresponse = llm.query(\n    model=\"claude-sonnet-4.5\",\n    query=\"Fun facts about pelicans\",\n    stop_sequences=[\"beak\", \"feathers\"],\n)\n```\n\n## Development\n\nTo set up this plugin locally, first checkout the code. Then create a new virtual environment:\n```bash\ncd llm-anthropic\npython3 -m venv venv\nsource venv/bin/activate\n```\nNow install the dependencies and test dependencies:\n```bash\npip install -e . --group dev\n```\nTo run the tests:\n```bash\npytest\n```\n\nAlternatively, if you have [uv](https://github.com/astral-sh/uv) you can run tests without first creating a virtual environment like this:\n```bash\nuv run pytest\nuv run pytest -k test_tools\n```\n\nYou can also run the `llm` command in a `uv` managed environment like this:\n```bash\nuv run llm 'your prompt here'\n```\nTo enable debug logs while running ([like this](https://github.com/simonw/llm-anthropic/issues/54#issuecomment-3536842831)), set this environment variable:\n```bash\nexport ANTHROPIC_LOG=debug\n```\n\nThis project uses [pytest-recording](https://github.com/kiwicom/pytest-recording) to record Anthropic API responses for the tests.\n\nIf you add a new test that calls the API you can capture the API response like this:\n```bash\nPYTEST_ANTHROPIC_API_KEY=\"$(llm keys get anthropic)\" pytest --record-mode once\n```\nYou will need to have stored a valid Anthropic API key using this command first:\n```bash\nllm keys set anthropic\n# Paste key here\n```\nI use the following sequence:\n```bash\n# First delete the relevant cassette if it exists already:\nrm tests/cassettes/test_anthropic/test_thinking_prompt.yaml\n# Run this failing test to recreate the cassette\nPYTEST_ANTHROPIC_API_KEY=\"$(llm keys get claude)\" uv run pytest -k test_thinking_prompt --record-mode once\n# Now run the test again with --pdb to figure out how to update it\nuv run pytest -k test_thinking_prompt --pdb\n# Edit test\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimonw%2Fllm-anthropic","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsimonw%2Fllm-anthropic","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimonw%2Fllm-anthropic/lists"}