Quick Start
Prerequisites
Installation
Configuration
Update your Anthropic client initialization - just 2 lines:Making Requests
Layer supports three ways to specify your gate:- Using gateId (Recommended)
- Using model field
- Using header
Requires
@ts-ignore comment for TypeScript, but provides the clearest intent.Streaming Example
Streaming works exactly like the standard Anthropic SDK:What’s Supported
Streaming
Streaming
Full support for
stream: true with identical behavior to AnthropicTool Use
Tool Use
Works across all providers - Layer handles format conversion
Vision
Vision
Image inputs in messages fully supported
All Message Types
All Message Types
System prompts, user, and assistant messages all supported
Standard Parameters
Standard Parameters
temperature, max_tokens, top_p, and other Anthropic parametersUsage & Cost Tracking
Usage & Cost Tracking
Standard
response.usage with token counts, plus Layer’s cost fieldLanguage Examples
Migration Guide
Follow these steps to migrate an existing Anthropic application:1. Update Client Initialization
Find where you initialize the Anthropic client and update it:2. Add Gate ID
AddgateId to your message calls:
3. Update Environment Variables
.env
4. Test & Deploy
- Test in development
- Verify requests appear in Layer dashboard
- Check cost tracking is working
- Deploy to production
Easy Rollback: If anything breaks, revert the 2 changes (
baseURL + apiKey) - takes 30 seconds.Advanced Usage
Multiple Gates
Use different gates based on the task:Environment-Specific Configuration
Error Handling
How It Works
- You send → Anthropic SDK request to
https://api.uselayer.ai/anthropic/v1/messages - Layer receives → Validates gate, applies routing rules
- Layer routes → Sends to the model configured in your gate (Claude, GPT, Gemini, etc.)
- Provider responds → Returns response in provider’s format
- Layer normalizes → Converts back to Anthropic format
- You receive → Standard Anthropic response with added cost/metadata
FAQ
Do I need to change my code?
Do I need to change my code?
No. Just change
baseURL and apiKey in the Anthropic client initialization.Can I still use Anthropic directly?
Can I still use Anthropic directly?
Yes. Just revert
baseURL and apiKey to Anthropic values.Does streaming work?
Does streaming work?
Yes.
stream: true works exactly like Anthropic.Can I use GPT or Gemini?
Can I use GPT or Gemini?
Yes. Configure your gate to use any model — your code stays the same.
What about tool use?
What about tool use?
Fully supported. Layer handles the conversion across all providers.
Do I need the Layer SDK?
Do I need the Layer SDK?
No. This approach uses only the Anthropic SDK.
Comparison: Anthropic SDK vs Layer SDK
| Feature | Anthropic SDK + Layer | Layer SDK |
|---|---|---|
| Migration Effort | 2 lines of code | Full refactor |
| API Format | Anthropic format | Layer native format |
| Use Case | Drop-in replacement | New projects |
| Multi-modal | Chat only | Chat, image, video, audio |
| Streaming | ✓ | ✓ |
| Tool Use | ✓ | ✓ |
| Cost Tracking | ✓ | ✓ |
| Admin Operations | ✗ | ✓ (via Admin SDK) |
- Existing Anthropic apps → Use Anthropic SDK + Layer (this guide)
- New projects → Use Layer SDK for full feature set