# API Key 使用教程

### 一、进入API Key页面，点击添加令牌

<figure><img src="/files/6rRzqpMWu5NoJV0yY5JR" alt=""><figcaption></figcaption></figure>

### 二、在添加令牌页面，进行设置。然后点击确定。

{% hint style="info" %}
注意：设置无限额度，指的是这个令牌没有额度限制，但是需要保证您有算力值。如果算力值不足，即使令牌设置没有限制，也是无法使用的。
{% endhint %}

<figure><img src="/files/RM3LqI3lV7TRuLwDcUA4" alt=""><figcaption></figcaption></figure>

### 三、此时我们可以在这个页面看到查看key以及BaseUrl地址。

{% hint style="info" %}
常见报错1：

如果BaseUrl的地址访问不通，可以把https改成http就好了。如下：

<http://api.aihao123.cn/luomacode-api/open-api/>
{% endhint %}

{% hint style="info" %}
常见报错2：

openai.NotFoundError: Error code: 404 - {'msg': '当前操作需要登录\~', 'code': 204}

如果出现这个报错，请用下面的BaseUrl：

<https://api.aihao123.cn/luomacode-api/open-api/v1>
{% endhint %}

{% hint style="info" %}
理由：因为不同的框架会对BaseUrl的拼接有不同的封装程度，有的框架结尾会自动拼接v1，有的不会拼接v1。

<https://api.aihao123.cn/luomacode-api/open-api/v1>

<https://api.aihao123.cn/luomacode-api/open-api/>

所以请多尝试。如有问题请[加群反馈](/she-qu-gong-jian/guan-fang-jiao-liu-qu-dao.md)。
{% endhint %}

<figure><img src="/files/ur0EPiy7EXWKuP1XcqIb" alt=""><figcaption></figcaption></figure>

### &#x20;四、使用代码调用（Python）

#### （1）这是直接调用，没有设置系统提示词的代码

```python
from openai import OpenAI
client = OpenAI(
    api_key = "本平台生成的key",
    base_url = ""
)

response = client.chat.completions.create(
    messages=[
        {'role': 'user', 'content': "鲁迅为什么打周树人？"},
    ],
    model='gpt-4',
    stream=True
)

for chunk in response:
    print(chunk.choices[0].delta.content, end="", flush=True)
```

#### （2）这是一个简单的项目，包含了系统提示词的代码。

主要实现的是：根据用户反馈的问题，用GPT进行问题分类

```python
from openai import OpenAI

# 创建OpenAI客户端
client = OpenAI(
    api_key="your_api_key",  # 你自己创建创建的Key
    base_url="your_base_url"  # 你的base_url
)

def api(content):
    print()
    
    # 这里是系统提示词
    sysContent = f"请对下面的内容进行分类，并且描述出对应分类的理由。你只需要根据用户的内容输出下面几种类型：bug类型,用户体验问题，用户吐槽." \
                 f"输出格式:[类型]-[问题:{content}]-[分析的理由]"
    response = client.chat.completions.create(
        messages=[
            # 把系统提示词传进来sysContent
            {'role': 'system', 'content': sysContent},
            # 把用户提示词传进来content
            {'role': 'user', 'content': content},
        ],
        # 这是模型
        model='gpt-4',
        stream=True
    )

    for chunk in response:
        print(chunk.choices[0].delta.content, end="", flush=True)


if __name__ == '__main__':
    content = "这个页面不太好看"
    api(content)
```

### 五、完整模型名称大全

#### 官方扣费标准 · 无任何倍率

{% hint style="info" %}
在这个智能世界里，您有机会塑造属于自己的未来。我们热切期待着您每一次的创新，让我们携手共建人工智能的新时代。 我们承诺严格遵守官方扣费标准，绝无任何额外费用。每一次请求都会按照官方标准透明扣费，确保您清晰明了地了解每次消费，无需担心任何其他问题。让您放心体验，畅享智能技术带来的便捷与乐趣。
{% endhint %}

<table><thead><tr><th width="272">模型名称</th><th width="196">价格（USD/1K tokens）</th><th width="202">价格（USD/1K tokens）</th><th>备注</th></tr></thead><tbody><tr><td>gpt-3.5-turbo</td><td>0.0015</td><td>0.003</td><td></td></tr><tr><td>gpt-3.5-turbo-1106</td><td>0.001</td><td>0.002</td><td></td></tr><tr><td>gpt-3.5-turbo-0125</td><td>0.001</td><td>0.003</td><td></td></tr><tr><td>gpt-3.5-16K</td><td>0.003</td><td>0.006</td><td></td></tr><tr><td>gpt-4</td><td>0.03</td><td>0.06</td><td></td></tr><tr><td>gpt-4-1106-preview</td><td>0.01</td><td>0.03</td><td></td></tr><tr><td>gpt-4-0125-preview</td><td>0.01</td><td>0.03</td><td></td></tr><tr><td>gpt-4-1106-vision-preview</td><td>0.01</td><td>0.03</td><td></td></tr><tr><td>gpt-4-turbo-2024-04-09</td><td>0.03</td><td>0.09</td><td></td></tr><tr><td>gpt-4o-2024-05-13</td><td>0.01</td><td>0.03</td><td>（最强）</td></tr><tr><td>gpt-4-32K</td><td>0.06</td><td>0.12</td><td></td></tr><tr><td>claude-2</td><td>0.0110</td><td>0.0327</td><td></td></tr><tr><td>claude-3-opus-20240229</td><td>0.06</td><td>0.12</td><td></td></tr><tr><td>claude-3-sonnet-20240229</td><td>0.06</td><td>0.12</td><td></td></tr><tr><td>还有100+模型型号也都支持...</td><td>...</td><td>...</td><td></td></tr></tbody></table>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://doc.nyai.chat/api-key-shi-yong-jiao-cheng.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
