I am trying to setup a project for GQLPT (can't create new tag because << reputation), and in their "Get Started" docs, they have given steps which (as of now) are:
According to docs, the code to paste in the index.js file is
import { AdapterOpenAI } from "@gqlpt/adapter-openai";
import { GQLPTClient } from "gqlpt";
const client = new GQLPTClient({
typeDefs: `
type User {
id: ID!
name: String!
}
type Query {
user(id: ID!): User
}
`,
adapter: new AdapterOpenAI({
apiKey: process.env.OPENAI_API_KEY,
}),
});
async function main() {
await client.connect();
const query = "Find users by id 1";
const response = await client.generateQueryAndVariables(query);
console.log(response);
}
main();
However I have integrated the api within the code block just for testing,
const apiKey = "API-GOES-HERE"; // Replace with your actual API key
const client = new GQLPTClient({
typeDefs: `
type User {
id: ID!
name: String!
}
type Query {
user(id: ID!): User
}
`,
adapter: new AdapterAnthropic({
apiKey: apiKey, // Directly pass the embedded API key
}),
});
and also called
const { AdapterAnthropic } = require("@gqlpt/adapter-anthropic");
const { GQLPTClient } = require("gqlpt");
rather than using import.
The error I receive upon running node index.js
is as follows:
status: 400,
headers: {
'cf-cache-status': 'DYNAMIC',
'cf-ray': 'HIDDEN-BY-ME-FOR-ONLINE-POST-HEHE',
connection: 'keep-alive',
'content-length': '190',
'content-type': 'application/json',
date: 'Mon, 27 Jan 2025 11:48:31 GMT',
'request-id': 'HIDDEN-BY-ME-FOR-ONLINE-POST-HEHE',
server: 'cloudflare',
via: '1.1 google',
'x-robots-tag': 'none',
'x-should-retry': 'false'
},
request_id: 'HIDDEN-BY-ME-FOR-ONLINE-POST-HEHE',
error: {
type: 'error',
error: {
type: 'invalid_request_error',
message: 'Your credit balance is too low to access the Anthropic API. Please go to Plans & Billing to upgrade or purchase credits.'
}
}
}
I am using free tier for Anthropic API. OpenAI also gave same error. Is the problem an underlying one or am I simply using free tier and that is causing the error. (my first time using either API's)
I tried following the instructions here: https://www.gqlpt.dev/docs/getting-started and rather than setting environment variable, I hardcoded api in the index.js code.
Then I received error "Cannot use import statement outside a module" so I used const rather than import.
The error 401 changed to 400 and rest is shown in main post.
According to https://www.anthropic.com/pricing#claude-ai-plans, FREE tier only allows to "Talk to Claude on the web" and such. There is no FREE tier for API usage as per https://www.anthropic.com/pricing#anthropic-api, therefore you was asked for credits right from the start.