Anthropic Connector
Learn how to integrate Anthropic's AI models into your graph
Anthropic provides AI models for text understanding, reasoning, and safe conversations. The prebuilt Anthropic Connector provides a GraphQL interface for Anthropic's AI models and services, allowing you to integrate Anthropic's capabilities into your graph.
Connector capabilities
This Connector provides your graph access to the Anthropic API's Messages endpoints.
Prerequisites
To use the Connector, you need an Anthropic API key.
Try out the Connector
Use the Apollo Sandbox below to test out the Connector. This is the same interface you use locally to test your queries.
To use this sandbox you either need to add your Anthropic key as a header or copy and paste placeholder values.
Add your Anthropic API Key
- In the sandbox, below the Operations panel, open the Headers tab then click Add a new header.
- Add a new header with the name
x-api-key
and your Anthropic API key as the value. - Select and run a query from the Documentation tab to test.
Use placeholder values
- Copy and paste the following into the Operations panel in Sandbox:GraphQL
mutation GenerateStory($about: [MessageInput]!) { createMessage(messages: $about) { id model role usage { inputTokens outputTokens } content { type text } } }
- Copy and paste the following into the Variables panel below Operations:JSON
{ "about": [ { "role": "USER", "content": "The story about Apollo" } ] }
- Run the operation.
Getting started
If you haven't already, create a new graph in GraphOS.
Copy the
supergraph.yaml
androuter.yaml
files from the Connector to replace the files created by runningrover init
.Set your Anthropic API key as an environment variable in your terminal:
terminalexport ANTHROPIC_API_KEY=....
Run
rover dev
to start the local development session:terminalAPOLLO_KEY=service:My-Graph-s1ff1u:•••••••••••••••••••••• \ APOLLO_GRAPH_REF=My-Graph-s1ff1u@main \ rover dev --supergraph-config supergraph.yaml --router-config router.yaml
You're all set! Open http://localhost:4000
to query your graph using Apollo Sandbox.
Adding to an existing graph in GraphOS
To add this Connector to an existing graph, publish the schema anthropic.graphql
file to your graph ref using rover subgraph publish
:
APOLLO_KEY=service:My-Graph-s1ff1u:•••••••••••••••••••••• \
rover subgraph publish My-Graph-s1ff1u@main --name anthropic --schema anthropic.graphql --routing-url http://anthropic
Setup VS Code task runner
Once you've set up the VS Code task runner, you can execute the Tasks: Run Task
command in VS Code to run the rover dev
task.
Edit your .vscode/settings.json
to include the following Anthropic-specific key:
{
"terminal.integrated.profiles.osx": {
"graphos": {
"path": "zsh",
"args": ["-l"],
"env": {
"ANTHROPIC_API_KEY": "",
"APOLLO_KEY": ""
}
}
},
"terminal.integrated.defaultProfile.osx": "graphos"
}
Alternatively, you can open a new terminal window in VS Code with the graphos
profile, then run rover dev --supergraph-config supergraph.yaml --router-config router.yaml
.
Contributing
The Connectors Community welcomes contributions to this Connector or to expand the library. For instructions on how to contribute, see the contributing guide.
Modules to contribute
The following features can be added to this Connector:
Support for newer Claude models
Stream response handling
Additional Anthropic API endpoints
See the Anthropic API Documentation for other features to implement.