LFM 3B - API, Providers, Stats

内容

OpenRouter provides an OpenAI-compatible completion API to 0 models & providers that you can call directly, or using the OpenAI SDK. Additionally, some third-party SDKs are available.

In the examples below, the OpenRouter-specific headers are optional. Setting them allows your app to appear on the OpenRouter leaderboards.

Using the OpenAI SDK

import OpenAI from "openai"
const openai = new OpenAI({
 baseURL: "https://openrouter.ai/api/v1",
 apiKey: "<OPENROUTER_API_KEY>",
 defaultHeaders: {
 "HTTP-Referer": "<YOUR_SITE_URL>", // Optional. Site URL for rankings on openrouter.ai.
 "X-Title": "<YOUR_SITE_NAME>", // Optional. Site title for rankings on openrouter.ai.
 }
})
async function main() {
 const completion = await openai.chat.completions.create({
 model: "liquid/lfm-3b",
 messages: [
 {
 "role": "user",
 "content": "What is the meaning of life?"
 }
 ]
 })
 console.log(completion.choices[0].message)
}
main()

Using the OpenRouter API directly

fetch("https://openrouter.ai/api/v1/chat/completions", {
 method: "POST",
 headers: {
 "Authorization": "Bearer <OPENROUTER_API_KEY>",
 "HTTP-Referer": "<YOUR_SITE_URL>", // Optional. Site URL for rankings on openrouter.ai.
 "X-Title": "<YOUR_SITE_NAME>", // Optional. Site title for rankings on openrouter.ai.
 "Content-Type": "application/json"
 },
 body: JSON.stringify({
 "model": "liquid/lfm-3b",
 "messages": [
 {
 "role": "user",
 "content": "What is the meaning of life?"
 }
 ]
 })
});

Using third-party SDKs

For information about using third-party SDKs and frameworks with OpenRouter, please see our frameworks documentation.

See the Request docs for all possible parameters, and Parameters for recommended values.

总结
OpenRouter 提供了一个与 OpenAI 兼容的完成 API,用户可以直接调用或使用 OpenAI SDK。文章介绍了如何使用 OpenAI SDK 和 OpenRouter API 进行请求。使用 OpenAI SDK 时,需要设置基本 URL 和 API 密钥,并可选地添加一些头信息以便在 OpenRouter 排行榜上显示应用。示例代码展示了如何发送消息并获取回复。直接使用 OpenRouter API 时,用户需要发送 POST 请求,包含授权信息和消息内容。文章还提到可以使用第三方 SDK,具体信息可参考相关文档。总之,OpenRouter 提供了灵活的接口供开发者使用,支持多种调用方式。