and you mentioned you're getting a "not found" error (likely HTTP 404).
Why are you getting "not found"?
The Hugging Face Inference API requires authentication and often a slightly different URL format.
Missing API Key & Authorization header
The Hugging Face API requires an API token sent via an Authorization header:
code
Authorization: Bearer YOUR_HF_API_TOKEN
Without this, the API will return errors like 401 Unauthorized or even 404 Not Found if the endpoint is protected.
Using the correct endpoint URL
The current URL https://api-inference.huggingface.co/models/bigscience/bloom is for general inference, but it may behave differently depending on model availability and access rights.
Make sure you have access to the model bigscience/bloom.
Hugging Face also recommends using the "inference" endpoint like:
Authorization is already present in my code. what should b API url ?
Assistant
Thanks for clarifying that the Authorization header is already present in your code. Given that, the likely cause for the 404 Not Found error is that the API URL you are using is incorrect or incomplete for the Hugging Face Inference API.
Correct Hugging Face API URL for inference
For Hugging Face Inference API, the typical endpoint format for a specific model is:
Confirm that the model allows API inference (and that your token has the rights).
Model backend status
Hugging Face sometimes disables or retires models from the inference API backend, or the model might be set up in a way it cannot be accessed via API yet.
Try a known public model
To isolate the problem, try invoking a simpler, smaller model that is freely accessible, such as:
Use the model ID from the page for your Apex calls, e.g., bigscience/bloom.
Verify API access and model availability.
If you want me to recommend specific good models for text generation or SOQL query generation, just ask!
User
yes please provide good models
Assistant
Certainly! Here are some Hugging Face models well-suited for generating or assisting with text generation tasks like SOQL query generation.
Recommended Hugging Face Models for Text Generation (including code or query generation)
Model Name & ID
Description
Notes
gpt2 (gpt2)
OpenAI GPT-2 small model. Good for general text generation with fast inference and publicly accessible.
Lightweight, good baseline model.
distilgpt2 (distilgpt2)
Smaller, faster distilled version of GPT-2.
Good if speed or smaller size is required.
Salesforce/codegen-350M-multi
Salesforce’s code generation model trained on multiple programming languages and natural language, useful for generating queries/code snippets.
Suitable for code and query generation. Free to use.
EleutherAI/gpt-neo-1.3B
Open-source GPT-Neo 1.3B parameter model.
Larger and more powerful than GPT-2, good generation quality.
bigscience/bloom
Very large language model, 176B params, multilingual general text generation.
Powerful, but requires high API access. Might be restricted for your account.
microsoft/CodeGPT-small-py
Smaller GPT model fine-tuned on code (Python).
Useful if you want code-style generation.
Salesforce/codegen-2B-multi
Larger Salesforce CodeGen model (2 billion params), well-suited for code and query generation.
Bigger model than 350M version, better quality but slower.
What to choose for SOQL query generation in Salesforce Apex:
If you want quick and free access, start with:
gpt2
distilgpt2
Salesforce/codegen-350M-multi
If you have paid subscription or advanced access and want more powerful models:
bigscience/bloom (if accessible)
EleutherAI/gpt-neo-1.3B
Salesforce/codegen-2B-multi
Example: Using Salesforce/codegen-350M-multi in your Apex code:
User
yes please create apex callout for AuraEnabled
Assistant
Certainly! Below is a complete example of an @AuraEnabled Apex method that takes a user question, sends it as a prompt to the Salesforce/codegen-350M-multi Hugging Face inference API, receives the generated SOQL query, then runs the SOQL query and returns the results serialized as JSON.
Assumptions
You have a Named Credential configured in Salesforce called HuggingFace with the base URL: https://api-inference.huggingface.co/models/Salesforce/codegen-350M-multi
and it contains your Hugging Face Bearer token configured as an Authentication header.
(This simplifies Apex callout and avoids hardcoding tokens.)
Apex Class Example
apex
User
why i am getting not foudn always ? i have already created acess token & passing as request.setHeader('Authorization', 'Bearer hdfhdfdf');
Assistant
If you are always getting a 404 Not Found response even though you have added the Authorization header with your Hugging Face API token, here are the key things to verify and troubleshoot:
1. Check the full endpoint URL
The endpoint URL must include the model name exactly and the full inference API path.
Go to the Headers tab and add the following headers:
Key
Value
Authorization
Bearer YOUR_HF_API_TOKEN
Content-Type
application/json
Replace YOUR_HF_API_TOKEN with your actual Hugging Face API access token.
5. Add the request body
Go to the Body tab.
Select raw
Select JSON from the dropdown on the right
Paste the JSON payload:
json
{
"inputs": "Your prompt here"
}
Example:
json
{
"inputs": "You are an AI agent helping users query audit-related data in Salesforce. Generate a SOQL query to find assessments with status Completed."
}
6. Send the Request
Click Send
7. View the Response
User
{"inputs":"list account name"}
not found in postman
Assistant
Thanks for sharing your exact test input and the fact that you're getting "not found" in Postman. This suggests the call is reaching the server but the server can't find the resource you're requesting—almost always a 404 Not Found.
Likely causes and ways to fix:
1. Verify your model ID (URL path) correctness
You wrote you sent:
code
POST https://api-inference.huggingface.co/models/Salesforce/codegen-350M-multi
Is that the actual exact URL in Postman? Or did you test it with just:
code
https://api-inference.huggingface.co/models/list account name
Make sure you do not put the prompt "list account name" as part of the URL path. It should be the request body only.
If you do exactly the above and still get "not found", it usually means your token does NOT have access to that model. Hugging Face returns 404 for unauthorized model access.
Alternatively, the model might not exist or the model ID is misspelled or different in case.
3. Try with a public model that requires no subscription
Thanks for confirming the URL (https://api-inference.huggingface.co/models/Salesforce/codegen-350M-multi) is correct.
Since you are still getting "not found" when calling the endpoint with that URL and a valid Authorization token, here are the reasons and next steps:
1. The "not found" is very likely a model access issue
Hugging Face returns HTTP 404 Not Found when your API token is not authorized to access that model.
The token itself may be valid for general use, but that specific model (Salesforce/codegen-350M-multi) is likely restricted and requires explicit access or paid subscription.
If you’re getting "not found" even when calling the public model API at https://api-inference.huggingface.co/models/distilgpt2 using a valid token with write permission, here are some detailed troubleshooting steps and explanations tailored to your situation:
1. Verify Token Permissions vs. Usages
Write permission on a Hugging Face token usually means permission to upload models or datasets.
For inference API calls, your token needs “Read” scope (for accessing models), which is generally included by default.
Make sure your token has read permission enabled as well.
On https://huggingface.co/settings/tokens, check if your token includes Read and Inference API scopes (or equivalent).
2. Try an entirely new token with minimum necessary scopes
Generate a new token.
Select only Read scope plus Inference API access if shown.
Use this token for your Postman call.
3. Confirm the API call format with an example cURL
Run this cURL from your terminal (replace YOUR_TOKEN with your token):
Expect a valid response — a JSON array with the generated text.
Notes:
write scope allows uploading models or datasets but does NOT grant inference API access.
For inference API calls, read scope is mandatory.
If you want access to premium models (like Salesforce/codegen-350M-multi), you also need a paid subscription or explicit access granted by Hugging Face.
TL;DR:
Delete your old token.
Create new token with read permission.
Use new token in Authorization header.
Test again.
If you want, I can provide a minimal working curl or Postman example for this once you have the right token!
User
can u provide free model i can use for my salesforce application
Assistant
Certainly! For your Salesforce application where you want to generate SOQL queries from user prompts, and considering you need a free model accessible via Hugging Face’s inference API, here are some good options you can use without requiring paid subscription or special access:
Free & Public Hugging Face Models for Text Generation
Model Name & Endpoint
Description
Notes
distilgpt2
Smaller distilled version of GPT-2
Lightweight and fast, supports general text generation. Very reliable free choice.
gpt2
The original GPT-2 base model
Good general purpose text generation, a bit larger than distilgpt2 but free.
EleutherAI/gpt-neo-125M
GPT-Neo smaller base model from EleutherAI
Larger than GPT-2 small, open-source, good language generation quality.
sshleifer/tiny-gpt2
Tiny GPT-2 variant
Very lightweight, suitable for quick tests, but lower quality.
Recommended for your use case
distilgpt2 is the best balance of quality and availability for free API use.
Sample usage for distilgpt2 in Salesforce Apex
apex
Http http = new Http();
HttpRequest req = new HttpRequest();
req.setEndpoint('https://api-inference.huggingface.co/models/distilgpt2');
req.setMethod('POST');
req.setHeader('Content-Type', 'application/json');
req.setHeader('Authorization', 'Bearer YOUR_HF_API_TOKEN');
Map<String, Object> payload = new Map<String, Object>{
'inputs' => 'Generate the SOQL query for user question: ' + userQuery
};
req.setBody(JSON.serialize(payload));
HttpResponse res = http.send(req);
System.debug('Status: ' + res.getStatusCode());
System.debug('Body: ' + res.getBody());
// Parse and handle response as needed...
If you’re getting a 404 “not found” error when calling the endpoint https://api-inference.huggingface.co/models/gpt2 via Postman, but expecting it to work, here are key points and checks:
1. Hugging Face endpoint format and current API
The Hugging Face Inference API uses the URL pattern:
If you want, I can help you tailor your prompt or Apex callout specifically for these models!
public with sharing class SOQLGeneratorService {
@AuraEnabled(cacheable=false)
public static String generateAndRunSOQL(String userQuery) {
Http http = new Http();
HttpRequest request = new HttpRequest();
// Named Credential base URL + model path
// Make sure your Named Credential is named HuggingFace and points to:
// https://api-inference.huggingface.co/models/Salesforce/codegen-350M-multi
String endpoint = 'callout:HuggingFace';
// Build the prompt, instruct the model to generate only the SOQL query
String prompt = 'You are an AI agent helping users query audit-related data in Salesforce. ' +
'There are two objects:\n' +
'1. argrc__Assessment__c with fields: Name, argrc__Start_Date__c, argrc__End_Date__c, Factory_Name__c, Factory_City__c, Factory_Country__c, argrc__Assessment_Status__c, Job_Type__c\n' +
'2. argrc__Assessment_Stakeholder__c with fields: Name, argrc__Stakeholder__c, argrc__Role__c, argrc__Assessment__c (lookup to argrc__Assessment__c)\n' +
'Generate a SOQL query based on the user’s question. Return only the SOQL query. Do not explain.\n' +
'User Question: ' + userQuery;
// Prepare HTTP request
request.setEndpoint(endpoint);
request.setMethod('POST');
request.setHeader('Content-Type', 'application/json');
// Authorization header handled by Named Credential
// Request body as JSON
Map<String, Object> bodyMap = new Map<String, Object>{
'inputs' => prompt
};
request.setBody(JSON.serialize(bodyMap));
try {
HttpResponse response = http.send(request);
Integer statusCode = response.getStatusCode();
if (statusCode != 200) {
// Return error response from Hugging Face API
return 'Error from Hugging Face API. Status code: ' + statusCode + ' Body: ' + response.getBody();
}
// Parse response:
// The typical response is a list of objects like:
// [ { "generated_text": "SELECT ... FROM ... WHERE ..." } ]
List<Object> jsonResponse = (List<Object>) JSON.deserializeUntyped(response.getBody());
if (jsonResponse.isEmpty()) {
return 'No generated text from Hugging Face model.';
}
Map<String, Object> firstElement = (Map<String, Object>) jsonResponse[0];
String generatedSOQL = (String) firstElement.get('generated_text');
if (String.isBlank(generatedSOQL)) {
return 'Empty SOQL query generated.';
}
// Debug log optionally
System.debug('Generated SOQL query: ' + generatedSOQL);
// Run the generated SOQL query
List<SObject> queryResults = Database.query(generatedSOQL);
// Serialize results to JSON and return
return JSON.serialize(queryResults);
} catch (Exception ex) {
return 'Exception occurred: ' + ex.getMessage();
}
}
}
How to configure Named Credential for HuggingFace
Go to Setup > Named Credentials > New Named Credential.
Paste your Hugging Face API token in the Bearer Token field.
Save.
How to test from Lightning Aura Component or LWC
You can invoke this Apex method like this:
js
import generateAndRunSOQL from '@salesforce/apex/SOQLGeneratorService.generateAndRunSOQL';
generateAndRunSOQL({ userQuery: 'show me all assessments in New York with status Completed' })
.then(result => {
console.log('Query Results JSON:', result);
// parse JSON for display
})
.catch(error => {
console.error('Error:', error);
});
Notes
The model prompt instructs the AI to generate only the SOQL query, so you can safely do Database.query() on the returned string.
For security, be careful with executing dynamically generated queries—consider additional validation if needed.
The response is serialized as JSON string for easy consumption by UI components.
If you want me to provide a Lightning Web Component example or Aura component code as well, just let me know!
4. Try a known public model to verify your code
Try a simpler, unrestricted public model like distilgpt2 to confirm your code and token works:
Replace with your token and try this to isolate token/endpoint issues.
Summary / Checklist:
Item
Action
Endpoint URL
Must be https://api-inference.huggingface.co/models/YourModelId
Auth Header
Authorization: Bearer YOUR_VALID_TOKEN
Token Permissions
Verify token has rights for the model (try simpler public models as a sanity check)
Remote Site / Named Credential
Ensure Salesforce allows callout to Hugging Face API
API Response Logging
Log full response and status code for clues
If you want, share the exact endpoint, token usage (mask sensitive parts), and the debug logs of your response status and body, and I can help you debug further!
Status code should be 200
Response body will be JSON like:
json
[
{
"generated_text": "SELECT Id, Name FROM argrc__Assessment__c WHERE argrc__Assessment_Status__c = 'Completed'"
}
]
Troubleshooting
401 Unauthorized: Your API token is missing, invalid, or expired.
404 Not Found:
Check your URL is correct with full model ID.
Make sure your API token has permission to access that model.
Other errors: View the response body for error messages.
Example cURL (optional)
You can also generate a cURL command in Postman to test from a terminal:
Ensure the token is active and has inference API permissions (usually all tokens do).
If your account is free tier, some large models will be blocked.
Upgrade or request access if needed.
5. Testing further
If you want me to verify/model name or test a curl command for you, please share your model URL and token permissions status (don’t share token), I can help further.
Example working Postman setup (copy-paste tested with Hugging Face public endpoint):
Use exact /models/Salesforce/codegen-350M-multi. Check token.
Not found in body
Sent prompt in URL or wrong payload format
Make sure prompt is in JSON payload under "inputs" key.
Works with distilgpt2
Your token works, model access is the problem
Request access or choose a free public model for now.
Let me know if you want me to help generate a minimal curl or Postman config based on your current setup!
Alternatively, try a smaller CodeGen model that is freely accessible, for example: Salesforce/codegen-350M (without -multi) or other community-available variants.
5. Summary
Scenario
Explanation
Action
404 Not Found on Salesforce/codegen-350M-multi
You lack API inference access for this model
Check Hugging Face subscription & permissions
Works on distilgpt2 model
API token and usage are correct
Use free model or upgrade access
Still 404 on free models
Token likely invalid or expired
Regenerate API token, check headers and URL
Additional debugging tip:
When you get a 404 response in Postman, check response headers and body for any useful error messages.
Sometimes Hugging Face adds error info in the body like:
json
{"error":"Model not found or you do not have access to it."}
If you want, I can help you pick a working free model or assist you with writing viable Apex callout code for the free one.
Let me know if you want an example request or Apex code for a free model like distilgpt2 to help unblock you!
Body (raw JSON):
json
{
"inputs": "list account name"
}
5. Possible reasons for still getting “not found”
Token invalid or expired
Try regenerating token.
Wrong request method (use POST only)
Make sure you are not doing GET or others.
Generate a new token with at least read permission.
Use this token in the Authorization header.
Important notes
These free models are general language models and not specialized in generating SOQL queries — your prompt engineering (the text you send in "inputs") matters a lot.
Due to model size and capability, output might be sometimes generic.
You can experiment with prompt wording to coax better SOQL outputs.
If you want better code/SQL-specific generation later, consider upgrading to more powerful models (like CodeGen) with a paid plan.
If you want, I can help you refine prompt examples and Apex callout logic tailored for distilgpt2 (or similar free models) to maximize SOQL query generation quality.
Let me know if you want me to provide a complete @AuraEnabled Apex example using distilgpt2!
Authorization = Bearer YOUR_TOKEN
Content-Type = application/json
Body (raw JSON):
json
{
"inputs": "generate a SOQL query for accounts in California"
}
6. Validate with cURL before Postman
Use cURL to isolate the issue:
bash
curl -X POST \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{"inputs":"generate a SOQL query for accounts in California"}' \
https://api-inference.huggingface.co/models/gpt2
If this returns the same 404, then the problem is with token or access rights.
7. Try a simple unauthenticated call (for some small models)
Some smaller models allow anonymous calls with limited rate; try without Authorization header.
If you get error "Invalid username or password." then token is required.
8. Final notes
If your token is new and you have confirmed scopes, and still get 404 for gpt2 (a very common public model), check for spelling mistakes or incorrect request method.