| [ Web Proxy ] |
| Viewing: https://adk.dev/integrations/../../workflows/../../evaluate/../../../agents/models/anthropic/ | [Back] [Original] |
[logo]
You can use Anthropic's Claude models with ADK in both Python and Java. Choose the path that matches your language and backend below.
You can use Claude models from Python in the following ways:
Claude wrapper. See Anthropic Claude on Agent
Platform.LiteLlm connector with an
Anthropic API key. See
LiteLLM.In Java, you can integrate Claude models directly using an Anthropic API key or
an Agent Platform backend with the ADK Claude wrapper class. You can also
access Claude through Google Cloud Agent Platform services; see Third-Party
Models on Agent Platform.
The following code examples show a basic implementation for using Claude models in your agents:
public static LlmAgent createAgent() {
AnthropicClient anthropicClient = AnthropicOkHttpClient.builder()
.apiKey("ANTHROPIC_API_KEY")
.build();
Claude claudeModel = new Claude(
"claude-sonnet-4-6", anthropicClient
);
return LlmAgent.builder()
.name("claude_direct_agent")
.model(claudeModel)
.instruction("You are a helpful AI assistant powered by Anthropic Claude.")
.build();
}
com.google.adk.models.Claude wrapper relies
on classes from Anthropic's official Java SDK, typically included as
transitive dependencies. For more information, see the Anthropic Java
SDK.Instantiate com.google.adk.models.Claude, providing the desired Claude model
name and an AnthropicOkHttpClient configured with your API key. Then, pass the
Claude instance to your LlmAgent, as shown in the following example:
import com.anthropic.client.AnthropicClient;
import com.google.adk.agents.LlmAgent;
import com.google.adk.models.Claude;
import com.anthropic.client.okhttp.AnthropicOkHttpClient; // From Anthropic's SDK
public class DirectAnthropicAgent {
private static final String CLAUDE_MODEL_ID = "claude-sonnet-4-6"; // Or your preferred Claude model
public static LlmAgent createAgent() {
// It's recommended to load sensitive keys from a secure config
AnthropicClient anthropicClient = AnthropicOkHttpClient.builder()
.apiKey("ANTHROPIC_API_KEY")
.build();
Claude claudeModel = new Claude(
CLAUDE_MODEL_ID,
anthropicClient
);
return LlmAgent.builder()
.name("claude_direct_agent")
.model(claudeModel)
.instruction("You are a helpful AI assistant powered by Anthropic Claude.")
// ... other LlmAgent configurations
.build();
}
public static void main(String[] args) {
try {
LlmAgent agent = createAgent();
System.out.println("Successfully created direct Anthropic agent: " + agent.name());
} catch (IllegalStateException e) {
System.err.println("Error creating agent: " + e.getMessage());
}
}
}
| Web Proxy Viewer | New URL | Original Page |