Anthropic
A Flyte task or app can call the Anthropic API with the anthropic Python SDK and a key from your own account.
| Setting | Value |
|---|---|
| Python package | anthropic |
| API key | API keys |
| Environment variable | ANTHROPIC_API_KEY |
Store your Anthropic API key
Run this command and paste the key at the prompt:
flyte create secret anthropic-api-key --project <your-project> --domain developmentCall Anthropic from a task
import os
import flyte
env = flyte.TaskEnvironment(
name="anthropic-inference",
image=flyte.Image.from_debian_base().with_pip_packages("anthropic"),
secrets=flyte.Secret(key="anthropic-api-key", as_env_var="ANTHROPIC_API_KEY"),
)
@env.task
async def summarize(text: str) -> str:
from anthropic import AsyncAnthropic
client = AsyncAnthropic(api_key=os.environ["ANTHROPIC_API_KEY"])
response = await client.messages.create(
model="claude-opus-5-5",
max_tokens=1000,
messages=[{"role": "user", "content": f"Summarize in two sentences:\n\n{text}"}],
)
return response.content[0].text
if __name__ == "__main__":
flyte.init_from_config()
run = flyte.run(summarize, text="First document...")
print(run.url)
Call Anthropic from an app
An AppEnvironment takes the same secrets argument, and the app reads the same environment variable. See Call the provider from an app.
Anthropic also has an OpenAI-compatible endpoint, which its docs describe as being for testing and comparing models, not production.
Route calls through the LLM Gateway
To add budgets, fallbacks, and guardrails, add Anthropic to the LLM Gateway using the same secret, then point your client at the gateway. See Choose direct calls or the gateway.