OpenRouterTeam / openrouter-examples

Examples of integrating the OpenRouter API
https://openrouter.ai/docs
MIT License
76 stars 10 forks source link

OpenRouter incompatible with new openai API #3

Closed jmizgajski closed 9 months ago

jmizgajski commented 9 months ago

following code yields a 404 on openai==1.3.5 which destroys compatibility with langchain and llama_index

client = OpenAI(
    default_headers={
        "HTTP-Referer": referer,
    },
    base_url="https://openrouter.ai/api/v1",
    api_key=open_router_key,
    max_retries = max_retries,
)
response = client.completions.create(
    prompt=prompt,
    model=self.model_name,
    max_tokens=self.max_tokens,
    temperature=self.temperature,
    n=self.n,
)
reply = response.choices[0].text

the request made looks like this in debugger - seems open-ai changed their endpoints

image

louisgv commented 9 months ago

Re:discord conversation, the python example is at: https://github.com/OpenRouterTeam/openrouter-examples-python/tree/main