400 CLIENT ERROR: BAD REQUEST

Hi, I’m encountering a 400 Bad Request error when trying to access the SambaNova API at https://api.sambanova.ai/v1/completions. I’ve checked the endpoint, headers, and payload formatting, but the error persists. Could anyone provide guidance on resolving this issue or common causes I might be overlooking?

@mkoduri73 I would suggest to use https://api.sambanova.ai/v1

Hi @durgesh.ojha ,

I have been following the instructions carefully, but I continue to encounter the same error. Attached below is the configuration file for my project. Could you kindly review it and provide your insights?

Thank you for your assistance.

Config.py:

from dotenv import load_dotenv
import os

load_dotenv()

class Config:
    # API Keys
    SAMBANOVA_API_KEY = os.getenv("SAMBANOVA_API_KEY")
    TAVILY_API_KEY = os.getenv("TAVILY_API_KEY")
    SERPAPI_API_KEY = os.getenv("SERPAPI_API_KEY")

    # Update MODELS dictionary
    MODELS = {
            "llama-3.1-405b-Instruct-8k": {
                "name": "Llama-3.1 405B",
                "max_tokens": 4096,
                "description": "Meta's Llama 3.1 405B model optimized for instruction following",
                "api_base": "https://api.sambanova.ai/v1",
                "timeout": 60,
                "max_retries": 3
            }
        }

    DEFAULT_MODEL = "llama-3.1-405b-Instruct-8k"

    SAMBANOVA_ENDPOINT = "https://api.sambanova.ai/v1"

    # Search settings
    MAX_RESULTS = 5
    SEARCH_TIMEOUT = 30  # seconds

    # Industry Categories
    INDUSTRY_CATEGORIES = [
        "Technology",
        "Healthcare",
        "Finance",
        "Retail",
        "Manufacturing",
        "Automotive",
        "Education",
        "Energy",
        "Telecommunications",
        "Real Estate",
        "Agriculture",
        "Entertainment",
        "Construction",
        "Transportation",
        "Hospitality",
        "Professional Services",
        "Media",
        "Pharmaceutical",
        "Consumer Goods",
        "Insurance"
    ]

    # Use Case Categories
    USE_CASE_CATEGORIES = {
        "Technology": [
            "Cloud Computing",
            "Cybersecurity",
            "AI/ML Applications",
            "DevOps",
            "Digital Transformation"
        ],
        "Healthcare": [
            "Patient Care",
            "Medical Diagnosis",
            "Healthcare Administration",
            "Telemedicine",
            "Drug Discovery"
        ],
        "Finance": [
            "Risk Management",
            "Trading",
            "Fraud Detection",
            "Customer Service",
            "Process Automation"
        ]
    }

    # Search Topics
    SEARCH_TOPICS = [
        "AI applications",
        "machine learning use cases",
        "digital transformation",
        "process automation",
        "innovation trends"
    ]

    @classmethod
    def get_industry_use_cases(cls, industry: str) -> list:
        """Get specific use cases for an industry."""
        return cls.USE_CASE_CATEGORIES.get(industry, [])

    @classmethod
    def check_api_keys(cls) -> dict:
        """Check which API keys are set"""
        return {
            "TAVILY_API_KEY": bool(cls.TAVILY_API_KEY),
            "SERPAPI_API_KEY": bool(cls.SERPAPI_API_KEY),
            "SAMBANOVA_API_KEY": True
        }

    @classmethod
    def get_model_config(cls, model_name: str) -> dict:
        """Get model configuration"""
        return cls.MODELS.get(model_name, cls.MODELS[cls.DEFAULT_MODEL])
1 Like

Do you have more details of the 400 error message, such as “invalid model”, “invalid value range”, etc?

Have you tried removing “-8k” and use “Meta-Llama-3.1-405B-Instruct”?

2 Likes

I removed “-8k” as instructed, but I’m still encountering the same issue. For reference, here is the exact error I’m receiving:

400 Client Error: Bad Request for url: https://api.sambanova.ai/v1/chat/completions

Hi @mkoduri73 ,please try changing base url to https://api.sambanova.ai/v1 instead of https://api.sambanova.ai/v1/chat/completions

Thanks & Regards

2 Likes

Also Model name has to be “Meta-Llama-3.1-405B-Instruct”

Thanks & Regards

2 Likes

@mkoduri73 that you for this post it caused us to notice that the following topic was categorized wrong so it was not viewable.

The error codes are now visible under

-Coby

1 Like

Thanks a lot, @coby.adams! Your help really solved the issue for me.

2 Likes

Hi . did you solve this problem. I have the same issue. If you have solved it, please help me!

1 Like

Hi @sanjarbahodirov9901,
If you can post the error that you are seeing regarding the issue, that would be helpful for us to debug.

Thanks and Regards

2 Likes

Thanks a lot for your reply, I solved it :blush:

3 Likes